|
|
<?php |
|
|
|
|
|
namespace Kanboard\Core; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Translator |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static $locales = array(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static $instance = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static function getInstance() |
|
|
{ |
|
|
if (self::$instance === null) { |
|
|
self::$instance = new self; |
|
|
} |
|
|
|
|
|
return self::$instance; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function translate($identifier) |
|
|
{ |
|
|
$args = func_get_args(); |
|
|
|
|
|
array_shift($args); |
|
|
array_unshift($args, $this->get($identifier, $identifier)); |
|
|
|
|
|
foreach ($args as &$arg) { |
|
|
$arg = htmlspecialchars((string) $arg, ENT_QUOTES, 'UTF-8', false); |
|
|
} |
|
|
|
|
|
return call_user_func_array( |
|
|
'sprintf', |
|
|
$args |
|
|
); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function translateNoEscaping($identifier) |
|
|
{ |
|
|
$args = func_get_args(); |
|
|
|
|
|
array_shift($args); |
|
|
array_unshift($args, $this->get($identifier, $identifier)); |
|
|
|
|
|
return call_user_func_array( |
|
|
'sprintf', |
|
|
$args |
|
|
); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function number($number) |
|
|
{ |
|
|
return number_format( |
|
|
$number, |
|
|
$this->get('number.decimals', 2), |
|
|
$this->get('number.decimals_separator', '.'), |
|
|
$this->get('number.thousands_separator', ',') |
|
|
); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function currency($amount) |
|
|
{ |
|
|
$position = $this->get('currency.position', 'before'); |
|
|
$symbol = $this->get('currency.symbol', '$'); |
|
|
$str = ''; |
|
|
|
|
|
if ($position === 'before') { |
|
|
$str .= $symbol; |
|
|
} |
|
|
|
|
|
$str .= $this->number($amount); |
|
|
|
|
|
if ($position === 'after') { |
|
|
$str .= ' '.$symbol; |
|
|
} |
|
|
|
|
|
return $str; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function get($identifier, $default = '') |
|
|
{ |
|
|
if (isset(self::$locales[$identifier])) { |
|
|
return self::$locales[$identifier]; |
|
|
} else { |
|
|
return $default; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static function load($language, $path = '') |
|
|
{ |
|
|
if ($path === '') { |
|
|
$path = self::getDefaultFolder(); |
|
|
} |
|
|
|
|
|
$filename = implode(DIRECTORY_SEPARATOR, array($path, $language, 'translations.php')); |
|
|
|
|
|
if (file_exists($filename)) { |
|
|
self::$locales = array_merge(self::$locales, require($filename)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static function unload() |
|
|
{ |
|
|
self::$locales = array(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static function getDefaultFolder() |
|
|
{ |
|
|
return implode(DIRECTORY_SEPARATOR, array(__DIR__, '..', 'Locale')); |
|
|
} |
|
|
} |
|
|
|