Lang/Items

* try to account for non-latin formating
 * use correct words provided by GlobalStrings.lua
This commit is contained in:
Sarjuuk
2017-04-13 17:55:27 +02:00
parent 5a45c6a5e6
commit 6fddbe40a4
8 changed files with 176 additions and 69 deletions

View File

@@ -59,19 +59,26 @@ class Lang
return null;
}
$vspfArgs = [];
$var = self::$$prop;
foreach ($args as $key)
foreach ($args as $arg)
{
if (!isset($var[$key]))
if (is_array($arg))
{
trigger_error('Lang - undefined key "'.$key.'" in property Lang::$'.$prop.'[\''.implode('\'][\'', $args).'\']', E_USER_WARNING);
$vspfArgs = $arg;
continue;
}
else if (!isset($var[$arg]))
{
trigger_error('Lang - undefined key "'.$arg.'" in property Lang::$'.$prop.'[\''.implode('\'][\'', $args).'\']', E_USER_WARNING);
return null;
}
$var = $var[$key];
$var = $var[$arg];
}
return $var;
return self::vspf($var, $vspfArgs);
}
public static function sort($prop, $group, $method = SORT_NATURAL)
@@ -342,6 +349,102 @@ class Lang
return number_format($number, $decimals, $seps[User::$localeId][1], $no1k ? '' : $seps[User::$localeId][0]);
}
private static function vspf($var, $args)
{
if (is_array($var))
{
foreach ($var as &$v)
$v == self::vspf($v, $args);
return $var;
}
if ($args)
$var = vsprintf($var, $args);
// line break
// |n
$var = str_replace('|n', '<br />', $var);
// color
// |c<aarrggbb><word>|r
$var = preg_replace('/\|cff([a-f0-9]{6})(.+?)\|r/i', '<span style="color: #$1;">$2</span>', $var);
// icon
// |T<imgPath>:0:0:0:-1|t - not used, skip if found
$var = preg_replace('/\|T[^\|]+\|t/', '', $var);
// hyperlink
// |H<hyperlinkStruct>|h<name>|h - not used, truncate structure if found
$var = preg_replace('/\|H[^\|]+\|h([^\|]+)\|h/', '$1', $var);
// french preposition : de
// |2 <word>
$var = preg_replace_callback('/\|2\s(\w)/i', function ($m) {
if (in_array(strtolower($m[1], ['a', 'e', 'h', 'i', 'o', 'u'])))
return "d'".$m[1];
else
return 'de '.$m[1];
}, $var);
// russian word cunjugation thingy
// |3-<number>(<word>)
$var = preg_replace_callback('/\|3-(\d)\(([^\)]+)\)/i', function ($m) {
switch ($m[0])
{
case 1: // seen cases
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
default: // passthrough .. unk case
return $m[1];
}
}, $var);
// numeric switch
// <number> |4<singular>:<plural>[:<plural2>];
$var = preg_replace_callback('/([\d\.\,]+)([^\d]*)\|4([^:]*):([^;]*);/i', function ($m) {
$plurals = explode(':', $m[4]);
$result = '';
if (count($plurals) == 2) // special case: ruRU
{
switch (substr($m[1], -1)) // check last digit of number
{
case 1:
// but not 11 (teen number)
if (!in_array($m[1], [11]))
{
$result = $m[3];
break;
}
case 2:
case 3:
case 4:
// but not 12, 13, 14 (teen number) [11 is passthrough]
if (!in_array($m[1], [11, 12, 13, 14]))
{
$result = $plurals[0];
break;
}
break;
default:
$result = $plurals[1];
}
}
else
$result = ($m[1] == 1 ? $m[3] : $plurals[0]);
return $m[1].$m[2].$result;
}, $var);
return $var;
}
}
?>