From 066e0791dfd3928ae5dd8b1bde3983eda6765ffa Mon Sep 17 00:00:00 2001 From: filip Date: Tue, 14 Jun 2016 22:17:39 +0200 Subject: a bit more flexible i18n helper --- langs.inc.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'langs.inc.php') diff --git a/langs.inc.php b/langs.inc.php index 42bb3a748..3a67aa463 100644 --- a/langs.inc.php +++ b/langs.inc.php @@ -500,7 +500,9 @@ function _r($string_for_translation, $sufix = '') * will just echo translation * * _g('Download Mageia %d!', array(5), 'a href="" style="color: blue;"') - * will echo blue link + * OR for only one member of array: + * _g('Download Mageia %s!', 5, 'a href="" style="color: blue;"') + * will both echo blue link * * _g("Hey there.", null, ' '); _g("How are you?") * will just echo translation: Hey there. How are you? @@ -509,7 +511,7 @@ function _r($string_for_translation, $sufix = '') * Do not exit the process. * * @param string $string_for_translation which we want to translate - * @param array $args for vsprintf + * @param array OR string $args for vsprintf/sprintf * @param string $tag_or_space HTML tag or space to append * * @return null @@ -517,8 +519,12 @@ function _r($string_for_translation, $sufix = '') function _g($string_for_translation, $args = null, $tag_or_space = '') { $translated_string = _r($string_for_translation); - if(is_array($args)) { - $translated_string = vsprintf($translated_string, $args); + if(!is_null($args)) { + if(is_array($args)) { + $translated_string = vsprintf($translated_string, $args); + } else { + $translated_string = sprintf($translated_string, $args); + } } if(!empty($tag_or_space) && $tag_or_space != ' ') { $tag_or_space_w_args = explode(' ', $tag_or_space); -- cgit v1.2.1