hledani v carovejch kodech
[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 //Wrap regexes with slashes
23 foreach($LOCALE_MESSAGES['regexp'] as $regexp => $replace) {
24 $LOCALE_MESSAGES['regexp']['/'.$regexp.'/i'] = $LOCALE_MESSAGES['regexp'][$regexp];
25 unset($LOCALE_MESSAGES['regexp'][$regexp]);
26 }
27
28 //Uppercase alternative
29 /*$LOCALE_MESSAGES['map'] = array_merge($LOCALE_MESSAGES['map'],
30 array_flip(array_map('strtoupper',array_flip(array_map('strtoupper',$LOCALE_MESSAGES['map']))))
31 );*/
32
33 /**
34 * !!! IMPORTANT NOTICE: This is ugly hack !!!
35 * !!! You should rather use PHP's internal gettext support !!!
36 */
37 function T($text) {
38 if(is_array($text)) return array_map('T',$text);
39
40 if(isset($GLOBALS['LOCALE_MESSAGES']['map'][$text])) return $GLOBALS['LOCALE_MESSAGES']['map'][$text];
41
42 $t = strtolower($text);
43 if(isset($GLOBALS['LOCALE_MESSAGES']['map'][$t])) return $GLOBALS['LOCALE_MESSAGES']['map'][$t];
44
45 $t = trim($t);
46 if(isset($GLOBALS['LOCALE_MESSAGES']['map'][$t])) return $GLOBALS['LOCALE_MESSAGES']['map'][$t];
47
48 $text = str_ireplace(array_keys($GLOBALS['LOCALE_MESSAGES']['map']), $GLOBALS['LOCALE_MESSAGES']['map'], $text);
49
50 return preg_replace(array_keys($GLOBALS['LOCALE_MESSAGES']['regexp']), $GLOBALS['LOCALE_MESSAGES']['regexp'], $text);
51 }
This page took 0.415241 seconds and 4 git commands to generate.