]> _ Git - cubist_locale.git/commitdiff
wip #5851 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 12 Apr 2023 06:40:40 +0000 (08:40 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 12 Apr 2023 06:40:40 +0000 (08:40 +0200)
src/Locale.php
src/LocalizedList.php

index 81ab8919b5a339d3582d49bfd179c0a241a2c33a..0ef528c57ed8eedc9ac85a499443bd2331bbca88 100644 (file)
@@ -2,10 +2,12 @@
 
 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);
+    }
 }
index 20dd1cae7760931794641af20eac36501d4a22d1..525e1e02916f5974131d4b7b17a8941293ab2716 100644 (file)
@@ -1,13 +1,11 @@
 <?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] = [];
         }
@@ -17,8 +15,7 @@ class LocalizedList
         return static::$_rawList[static::class][$locale];
     }
 
-    protected static function _getListPath()
-    {
+    protected static function _getListPath() {
         return '';
     }
 
@@ -26,8 +23,7 @@ class LocalizedList
      * @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)) {
@@ -37,12 +33,16 @@ class LocalizedList
         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]);
+    }
 }