a8c3d97e622313613a6031777f26a787f155939d
[mirrors/SokoMan.git] / lib / Locale.class.php
1 <?php
2 /*
3 * Harvie's PHP Localization
4 * Copyright (C) 2o11 Thomas Mudrunka
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 require_once(DIR_LOCALE.'/'.LOCALE_LANG.'/messages.inc.php');
21
22 foreach($LOCALE_MESSAGES['regexp'] as $regexp => $replace) {
23 $LOCALE_MESSAGES['regexp']['/'.$regexp.'/i'] = $LOCALE_MESSAGES['regexp'][$regexp];
24 unset($LOCALE_MESSAGES['regexp'][$regexp]);
25 }
26
27 /**
28 * !!! IMPORTANT NOTICE: This is ugly hack !!!
29 * !!! You should rather use PHP's internal gettext support !!!
30 */
31 function T($text) {
32 if(is_array($text)) return array_map('T',$text);
33
34 if(isset($GLOBALS['LOCALE_MESSAGES']['map'][$text])) return $GLOBALS['LOCALE_MESSAGES']['map'][$text];
35
36 $t = strtolower($text);
37 if(isset($GLOBALS['LOCALE_MESSAGES']['map'][$t])) return $GLOBALS['LOCALE_MESSAGES']['map'][$t];
38
39 $t = trim($t);
40 if(isset($GLOBALS['LOCALE_MESSAGES']['map'][$t])) return $GLOBALS['LOCALE_MESSAGES']['map'][$t];
41
42 $text = str_ireplace(array_keys($GLOBALS['LOCALE_MESSAGES']['map']), $GLOBALS['LOCALE_MESSAGES']['map'], $text);
43
44 return preg_replace(array_keys($GLOBALS['LOCALE_MESSAGES']['regexp']), $GLOBALS['LOCALE_MESSAGES']['regexp'], $text);
45 }
This page took 0.325766 seconds and 3 git commands to generate.