Skip to content

Commit b9e16dc

Browse files
committed
Translate only strings
1 parent e76c3fd commit b9e16dc

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

web/inc/i18n.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,30 @@ function _translate() {
1010
global $LANG;
1111

1212
$args = func_get_args();
13+
1314
$l = $args[0];
15+
if (empty($l)) return 'NO LANGUAGE DEFINED';
1416

15-
if (!$l) return 'NO LANGUAGE DEFINED';
1617
$key = $args[1];
18+
if (empty($key)) return '';
1719

18-
if (!isset($LANG[$l])) {
19-
require_once($_SERVER['DOCUMENT_ROOT'].'/inc/i18n/'.$l.'.php');
20+
// No translation needed
21+
if (!preg_match('/[a-z]/i', $key)) {
22+
return $key;
2023
}
2124

22-
if (!isset($LANG[$l][$key])) {
23-
$text=$key;
24-
} else {
25-
$text=$LANG[$l][$key];
25+
// Load language file (if not loaded yet)
26+
if (!isset($LANG[$l])) {
27+
require_once($_SERVER['DOCUMENT_ROOT']."/inc/i18n/$l.php");
2628
}
2729

30+
//if (!isset($LANG[$l][$key])) file_put_contents('/somewhere/something.log', "$key\n", FILE_APPEND);
31+
$text = isset($LANG[$l][$key]) ? $LANG[$l][$key] : $key;
32+
2833
array_shift($args);
29-
if (count($args)>1) {
34+
if (count($args) > 1) {
3035
$args[0] = $text;
31-
return call_user_func_array("sprintf",$args);
36+
return call_user_func_array('sprintf', $args);
3237
} else {
3338
return $text;
3439
}
@@ -42,8 +47,8 @@ function _translate() {
4247
*/
4348
function __() {
4449
$args = func_get_args();
45-
array_unshift($args,$_SESSION['language']);
46-
return call_user_func_array("_translate",$args);
50+
array_unshift($args, $_SESSION['language']);
51+
return call_user_func_array('_translate', $args);
4752
}
4853

4954
/**

0 commit comments

Comments
 (0)