diff options
author | eric <eric> | 2004-06-14 20:31:31 +0200 |
---|---|---|
committer | eric <eric> | 2004-06-14 20:31:31 +0200 |
commit | 5268aa5802366910b7900e83c9de7ffff2ff96d6 (patch) | |
tree | 4a28991fc8fe76ddab6b2b023b9f8c4990775f64 /web/lib/translator.inc | |
parent | 64520381cd4fb7c3a0684549292132911f9cf6f4 (diff) | |
download | aur-5268aa5802366910b7900e83c9de7ffff2ff96d6.tar.gz aur-5268aa5802366910b7900e83c9de7ffff2ff96d6.tar.xz |
Started adding i18n support
Diffstat (limited to 'web/lib/translator.inc')
-rw-r--r-- | web/lib/translator.inc | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/web/lib/translator.inc b/web/lib/translator.inc new file mode 100644 index 00000000..2d45f2ab --- /dev/null +++ b/web/lib/translator.inc @@ -0,0 +1,55 @@ +<? +# this include file provides support for i18n +# + +# usage: +# use the _() function for returning translated strings of +# text. The string can contain escape codes %h for HTML +# and %s for regular text. +# +# supporting scripts: +# there is a supporting script, web/utils/genpopo, that will +# parse the PHP files and create PHP include files that contain +# a mapping for each translated language. The include files +# have the form, +# +# $_t["en"]["My cat is large."] = "My cat is large."; +# $_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>")); + +include_once("common_po.inc"); + +function _($tag, $args=array()) { + global $_t; + global $LANG; + + # default to English if the lang hasn't been provided + # + if (!$LANG) { + $lang = "en"; + } else { + $lang = $LANG; + } + + # create the translation, if it doesn't exist, highlight it + # + $translated = $_t[$lang][$tag]; + if (!$translated) { + $translated = "<blink><b>_" . $tag . "_</b></blink>"; + } + + # replace escape substitutions + # + if (!empty($args)) { + while (list($k, $v) = each($args)) { + $translated = preg_replace("/\%[sh]/", $v, $translated, 1); + } + } + return $translated; +} + +# vim: ts=2 sw=2 noet ft=php +?> |