diff options
author | Lukas Fleischer <archlinux@cryptocrack.de> | 2011-08-15 10:16:46 +0200 |
---|---|---|
committer | Lukas Fleischer <archlinux@cryptocrack.de> | 2011-08-20 20:28:47 +0200 |
commit | b5d5687517c50d4bd6d8050a06b2902cf6c56b00 (patch) | |
tree | 883f3c9204d64873a23b21c93330acf087188fbb /web/lib | |
parent | ee4b398033da18a0cc2c57b0b2994ca16290a99e (diff) | |
download | aur-b5d5687517c50d4bd6d8050a06b2902cf6c56b00.tar.gz aur-b5d5687517c50d4bd6d8050a06b2902cf6c56b00.tar.xz |
web/lib/translator.inc.php: Use vsprintf() in __()
Remove hacky substitution code from __() and use vsprintf() instead
which will deal with all sorts of format strings properly.
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Diffstat (limited to 'web/lib')
-rw-r--r-- | web/lib/translator.inc.php | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/web/lib/translator.inc.php b/web/lib/translator.inc.php index 44c87bda..54e8cbbf 100644 --- a/web/lib/translator.inc.php +++ b/web/lib/translator.inc.php @@ -5,12 +5,11 @@ set_include_path(get_include_path() . PATH_SEPARATOR . '../lib' . PATH_SEPARATOR # usage: # use the __() function for returning translated strings of -# text. The string can contain escape codes %h for HTML -# and %s for regular text. +# text. The string can contain escape codes "%s". # # examples: # print __("%s has %s apples.", "Bill", "5"); -# print __("This is a %hmajor%h problem!", "<b>", "</b>"); +# print __("This is a %smajor%s problem!", "<b>", "</b>"); include_once('config.inc.php'); include_once('gettext.php'); @@ -26,23 +25,15 @@ function __() { $args = func_get_args(); # First argument is always string to be translated - $tag = $args[0]; + $tag = array_shift($args); # Translate using gettext_reader initialized before. $translated = $l10n->translate($tag); $translated = htmlspecialchars($translated, ENT_QUOTES); - $num_args = sizeof($args); - # Subsequent arguments are strings to be formatted - # - # TODO: make this more robust. - # '%%' should translate to a literal '%' - - if ( $num_args > 1 ) { - for ($i = 1; $i < $num_args; $i++) { - $translated = preg_replace("/\%[sh]/", $args[$i], $translated, 1); - } + if (count($args) > 0) { + $translated = vsprintf($translated, $args); } return $translated; |