| 1 |
<?php defined('ABSPATH') or die("Protected By WT!"); |
| 2 |
|
| 3 |
|
| 4 |
class WTSEC_LIBRARY_Localization |
| 5 |
{ |
| 6 |
|
| 7 |
public static function lmsg($lmsg,$values = []){ |
| 8 |
$default = 'en_US'; |
| 9 |
$lang = get_locale(); |
| 10 |
$path = self::getPath($lang); |
| 11 |
$messages = []; |
| 12 |
if(is_file($path)){ |
| 13 |
include $path; |
| 14 |
}else{ |
| 15 |
include self::getPath($default); |
| 16 |
} |
| 17 |
$keys = explode(".",$lmsg); |
| 18 |
foreach ($keys as $key) { |
| 19 |
if(!isset($messages[$key])){ |
| 20 |
break; |
| 21 |
} |
| 22 |
$messages = &$messages[$key]; |
| 23 |
} |
| 24 |
if(is_string($messages)){ |
| 25 |
foreach ($values as $_key => $value){ |
| 26 |
$messages = str_replace("%%".$_key."%%",$value,$messages); |
| 27 |
} |
| 28 |
return $messages; |
| 29 |
} |
| 30 |
return "[".$lmsg."]"; |
| 31 |
} |
| 32 |
|
| 33 |
public static function getPath($lang){ |
| 34 |
return WTSEC_PLUGIN_PATH.'resources/locales/'.$lang.'.php'; |
| 35 |
} |
| 36 |
} |