summaryrefslogtreecommitdiffstats
path: root/web/lib/translator.inc
diff options
context:
space:
mode:
authorLoui Chang <louipc.ist@gmail.com>2008-03-26 19:22:12 +0100
committerSimo Leone <simo@archlinux.org>2008-03-27 08:36:15 +0100
commitba9eda550340f7e1eb011b8ceea4d4cf33b762fa (patch)
tree868a4dc39e5405adefb533ae9ef9b14fb3f424f6 /web/lib/translator.inc
parent04dae8d94f846fe5b82d9261405cbc56a736ded3 (diff)
downloadaur-ba9eda550340f7e1eb011b8ceea4d4cf33b762fa.tar.gz
aur-ba9eda550340f7e1eb011b8ceea4d4cf33b762fa.tar.xz
New behaviour for translations. Function takes variable number of arguments.
The old string,array usage is still supported however. (for now) Signed-off-by: Loui Chang <louipc.ist@gmail.com> Signed-off-by: Simo Leone <simo@archlinux.org>
Diffstat (limited to 'web/lib/translator.inc')
-rw-r--r--web/lib/translator.inc36
1 files changed, 26 insertions, 10 deletions
diff --git a/web/lib/translator.inc b/web/lib/translator.inc
index bfae276c..93be9e56 100644
--- a/web/lib/translator.inc
+++ b/web/lib/translator.inc
@@ -17,31 +17,47 @@
# $_t["es"]["My cat is large."] = "Mi gato esta grande.";
#
# examples:
-# print __("%s has %s apples.", array("Bill", "5"));
-# print __("This is a %h%s%h problem!", array("<b>","major","</b>"));
+# print __("%s has %s apples.", "Bill", "5");
+# print __("This is a %h%s%h problem!", "<b>","major","</b>");
+#
+# deprecated usage:
+# print __("%s has %s apples.", array("Bill", "5"));
include_once("common_po.inc");
-function __($tag, $args=array()) {
+function __() {
global $_t;
global $LANG;
# create the translation, if it doesn't exist, highlight it
#
+ $args = func_get_args();
+
+ # First argument is always string to be translated
+ $tag = $args[0];
+
$translated = $_t[$LANG][$tag];
- if (!$translated) {
+ if (empty($translated)) {
# if it's a supported language, but there isn't a translation,
# alert the visitor to the missing translation.
#
- $translated = "<font color=\"red\"><b>_" . $tag . "_</b></font>";
+ $translated = "<b style=\"color: red\">_${tag}_</b>";
}
- # replace escape substitutions
- #
- if (!empty($args)) {
- while (list($k, $v) = each($args)) {
- $translated = preg_replace("/\%[sh]/", $v, $translated, 1);
+ # This condition is to reorganise the arguments in case of
+ # deprecated usage. __("string", array("string","string"))
+ if (!empty($args[1]) && is_array($args[1])) {
+ array_unshift($args[1], $tag);
+ $args = $args[1];
+ }
+
+ $num_args = sizeof($args);
+
+ # Subsequent arguments are strings to be formatted
+ if ( $num_args > 1 ) {
+ for ($i = 1; $i < $num_args; $i++) {
+ $translated = preg_replace("/\%[sh]/", $args[$i], $translated, 1);
}
}
return $translated;