namespace Cubist\Locale;
-class Locale extends LocalizedList
-{
- protected static function _getListPath()
- {
+class Locale extends LocalizedList {
+ protected static function _getListPath() {
return 'vendor/umpirsky/locale-list/data/$locale/locales.php';
}
+
+ public static function isLocale($code, $locale = 'en') {
+ return self::codeExists($code, $locale);
+ }
}
<?php
namespace Cubist\Locale;
-class LocalizedList
-{
+class LocalizedList {
protected static $_rawList = [];
protected static $_listPath = '';
- public static function getList($locale)
- {
+ public static function getList($locale) {
if (!isset(self::$_rawList[static::class])) {
self::$_rawList[static::class] = [];
}
return static::$_rawList[static::class][$locale];
}
- protected static function _getListPath()
- {
+ protected static function _getListPath() {
return '';
}
* @param string $locale
* @return array
*/
- protected static function _getList($locale)
- {
+ protected static function _getList($locale) {
$f = base_path(str_replace('$locale', $locale, static::_getListPath()));
if (!file_exists($f) || !is_file($f)) {
return include $f;
}
- public static function translate($code, $locale)
- {
+ public static function translate($code, $locale) {
$list = self::getList($locale);
if (isset($list[$code])) {
return $list[$code];
}
return null;
}
+
+ public static function codeExists($str, $locale = 'en') {
+ $list = self::getList($locale);
+ return isset($list[$str]);
+ }
}