m1k1oblog/app/lang.class.php

29 lines
594 B
PHP
Raw Permalink Normal View History

2017-06-19 17:51:59 +00:00
<?php
defined('PROJECT_PATH') OR exit('No direct script access allowed');
2017-06-19 17:51:59 +00:00
class Lang
{
2019-12-22 21:14:09 +00:00
const PATH = 'lang/';
2017-06-19 17:51:59 +00:00
private static $_dictionary = null;
2019-12-20 17:38:48 +00:00
2017-06-19 17:51:59 +00:00
public static function load($lang = 'en'){
2019-12-22 21:14:09 +00:00
$lang_file = APP_PATH.self::PATH.$lang.'.ini';
2017-06-19 17:51:59 +00:00
if(preg_match('/^[a-z]+$/', $lang) && is_readable($lang_file)){
self::$_dictionary = parse_ini_file($lang_file);
}
}
2019-12-20 17:38:48 +00:00
2017-06-19 17:51:59 +00:00
public static function get($key){
2020-11-06 08:58:32 +00:00
if(is_null(self::$_dictionary) || !array_key_exists($key, self::$_dictionary)){
2017-06-19 17:51:59 +00:00
return $key;
}
2019-12-20 17:38:48 +00:00
2017-06-19 17:51:59 +00:00
return self::$_dictionary[$key];
}
}
function __($key){
return Lang::get($key);
2020-08-24 19:50:00 +00:00
}