aboutsummaryrefslogtreecommitdiffstats
path: root/langs.inc.php
diff options
context:
space:
mode:
authorRomain d'Alverny <rda@mageia.org>2012-05-23 14:19:23 +0000
committerRomain d'Alverny <rda@mageia.org>2012-05-23 14:19:23 +0000
commitd7388077aa4d0c036d0ac00f2a49d6eadb34e8e4 (patch)
tree454feb84e8a250063f372b7057e3454cd038461c /langs.inc.php
parenteb97c3fc4f0503657478b35dfb4a48b588b637e8 (diff)
downloadwww-d7388077aa4d0c036d0ac00f2a49d6eadb34e8e4.tar
www-d7388077aa4d0c036d0ac00f2a49d6eadb34e8e4.tar.gz
www-d7388077aa4d0c036d0ac00f2a49d6eadb34e8e4.tar.bz2
www-d7388077aa4d0c036d0ac00f2a49d6eadb34e8e4.tar.xz
www-d7388077aa4d0c036d0ac00f2a49d6eadb34e8e4.zip
new .lang file loader; better output from _t()
Diffstat (limited to 'langs.inc.php')
-rw-r--r--langs.inc.php39
1 files changed, 36 insertions, 3 deletions
diff --git a/langs.inc.php b/langs.inc.php
index 1d592e3d7..7f8a53386 100644
--- a/langs.inc.php
+++ b/langs.inc.php
@@ -149,14 +149,14 @@ S;
* FIXME Yes, it's terribly wrong/evil to rely on an unknown global $_t.
* Solution? rethink the whole i18n thing in an integrated one.
*/
-function _t($s = null, $opt = null) {
+function _t($s = null, $opt = null, $post = ' ') {
if (!is_null($opt))
$_t = $opt;
else {
global $_t;
}
- return ($s == '' ? '---' : (array_key_exists($s, $_t) ? $_t[$s] : $s));
+ return ($s == '' ? '---' : (array_key_exists($s, $_t) ? $_t[$s] : $s)) . $post;
}
/**
@@ -174,7 +174,40 @@ function _h($s, $args = null, $tag = 'p') {
if (is_array($args))
$s = vsprintf(_t($s), $args);
- echo sprintf('<%s>%s</%s>', $tag, $s, $tag);
+ echo sprintf('<%s>%s</%s>', $tag, _t($s), $tag);
+}
+
+/**
+ * @param string $locale
+ * @param string $domain
+ *
+ * @return boolean
+ *
+ * @todo use i18n::get_fallback_language() or eq.
+*/
+function _lang_load($locale, $domain)
+{
+ $lang_file = sprintf('%s/langs/%s/%s.%s.lang', G_APP_ROOT, $locale, $domain, $locale);
+
+ if (file_exists($lang_file)) {
+
+ global $_t;
+
+ $f = file($lang_file);
+
+ foreach ($f as $k => $v) {
+
+ $C = substr($v, 0, 1);
+ if ($C === '#') continue;
+
+ if ($C === ';' && !empty($f[$k+1])) {
+ $_t[trim(substr($v, 1))] = trim($f[$k+1]);
+ }
+ }
+ return true;
+ }
+ error_log(sprintf('Could not find %s', $lang_file));
+ return false;
}
/**