|
|
@@ -11,21 +11,25 @@
|
|
|
class Minz_Translate {
|
|
|
/**
|
|
|
* $path_list is the list of registered base path to search translations.
|
|
|
+ * @var array<string>
|
|
|
*/
|
|
|
private static $path_list = array();
|
|
|
|
|
|
/**
|
|
|
* $lang_name is the name of the current language to use.
|
|
|
+ * @var string
|
|
|
*/
|
|
|
private static $lang_name;
|
|
|
|
|
|
/**
|
|
|
* $lang_files is a list of registered i18n files.
|
|
|
+ * @var array<string,array<string>>
|
|
|
*/
|
|
|
private static $lang_files = array();
|
|
|
|
|
|
/**
|
|
|
* $translates is a cache for i18n translation.
|
|
|
+ * @var array<string,mixed>
|
|
|
*/
|
|
|
private static $translates = array();
|
|
|
|
|
|
@@ -33,7 +37,7 @@ class Minz_Translate {
|
|
|
* Init the translation object.
|
|
|
* @param string $lang_name the lang to show.
|
|
|
*/
|
|
|
- public static function init($lang_name = null) {
|
|
|
+ public static function init(?string $lang_name = null): void {
|
|
|
self::$lang_name = $lang_name;
|
|
|
self::$lang_files = array();
|
|
|
self::$translates = array();
|
|
|
@@ -47,7 +51,7 @@ class Minz_Translate {
|
|
|
* Reset the translation object with a new language.
|
|
|
* @param string $lang_name the new language to use
|
|
|
*/
|
|
|
- public static function reset($lang_name) {
|
|
|
+ public static function reset(string $lang_name): void {
|
|
|
self::$lang_name = $lang_name;
|
|
|
self::$lang_files = array();
|
|
|
self::$translates = array();
|
|
|
@@ -60,7 +64,7 @@ class Minz_Translate {
|
|
|
* Return the list of available languages.
|
|
|
* @return array<string> containing langs found in different registered paths.
|
|
|
*/
|
|
|
- public static function availableLanguages() {
|
|
|
+ public static function availableLanguages(): array {
|
|
|
$list_langs = array();
|
|
|
|
|
|
self::registerPath(APP_PATH . '/i18n');
|
|
|
@@ -110,7 +114,7 @@ class Minz_Translate {
|
|
|
* Register a new path.
|
|
|
* @param string $path a path containing i18n directories (e.g. ./en/, ./fr/).
|
|
|
*/
|
|
|
- public static function registerPath($path) {
|
|
|
+ public static function registerPath(string $path): void {
|
|
|
if (!in_array($path, self::$path_list) && is_dir($path)) {
|
|
|
self::$path_list[] = $path;
|
|
|
self::loadLang($path);
|
|
|
@@ -121,7 +125,7 @@ class Minz_Translate {
|
|
|
* Load translations of the current language from the given path.
|
|
|
* @param string $path the path containing i18n directories.
|
|
|
*/
|
|
|
- private static function loadLang($path) {
|
|
|
+ private static function loadLang(string $path): void {
|
|
|
$lang_path = $path . '/' . self::$lang_name;
|
|
|
if (!file_exists($lang_path) || self::$lang_name == '') {
|
|
|
// The lang path does not exist, nothing more to do.
|
|
|
@@ -150,7 +154,7 @@ class Minz_Translate {
|
|
|
* Load the files associated to $key into $translates.
|
|
|
* @param string $key the top level i18n key we want to load.
|
|
|
*/
|
|
|
- private static function loadKey($key) {
|
|
|
+ private static function loadKey(string $key): bool {
|
|
|
// The top level key is not in $lang_files, it means it does not exist!
|
|
|
if (!isset(self::$lang_files[$key])) {
|
|
|
Minz_Log::debug($key . ' is not a valid top level key');
|
|
|
@@ -183,7 +187,7 @@ class Minz_Translate {
|
|
|
* @return string value corresponding to the key.
|
|
|
* If no value is found, return the key itself.
|
|
|
*/
|
|
|
- public static function t($key, ...$args) {
|
|
|
+ public static function t(string $key, ...$args): string {
|
|
|
$group = explode('.', $key);
|
|
|
|
|
|
if (count($group) < 2) {
|
|
|
@@ -238,7 +242,7 @@ class Minz_Translate {
|
|
|
/**
|
|
|
* Return the current language.
|
|
|
*/
|
|
|
- public static function language() {
|
|
|
+ public static function language(): string {
|
|
|
return self::$lang_name;
|
|
|
}
|
|
|
}
|
|
|
@@ -249,6 +253,6 @@ class Minz_Translate {
|
|
|
* @param string $key
|
|
|
* @param mixed ...$args
|
|
|
*/
|
|
|
-function _t($key, ...$args) {
|
|
|
+function _t(string $key, ...$args): string {
|
|
|
return Minz_Translate::t($key, ...$args);
|
|
|
}
|