Skip to content

Instantly share code, notes, and snippets.

@mamchenkov
Last active October 9, 2015 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamchenkov/3498902 to your computer and use it in GitHub Desktop.
Save mamchenkov/3498902 to your computer and use it in GitHub Desktop.
Nested sprintf() / vsprintf with gettext example
<?php
/**
* Example of sprintf()/vsprintf() with gettext
*/
/**
* String translation
*
* @param string $param String to translate
* @return string Translated string (surrounded by square brackets for visibility)
*/
function __($param) {
return '[' . $param . ']';
}
// Substring
$googleLink = sprintf('<a href="%s">%s</a>', 'http://www.google.com', __('Google'));
// Main string formatting with variable parameters count
$params = array('Leonid', $googleLink);
$message = vsprintf(__("Welcome, %s! Click on %s to finish."), $params);
echo $message;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment