diff --git a/.gitattributes b/.gitattributes index da09df5..182bbaa 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,6 +2,7 @@ .github/ export-ignore +bin/ export-ignore tests/ export-ignore .editorconfig export-ignore diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 17403d2..0438370 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -52,7 +52,7 @@ jobs: IS_DIRTY=1 vendor/bin/lang sync - php app/combined.php + php bin/combined.php { git add . && git commit -a -m "🔑 Synchronization of translation keys"; } || IS_DIRTY=0 diff --git a/app/combined.php b/bin/combined.php similarity index 83% rename from app/combined.php rename to bin/combined.php index f4d13d0..ea10cdd 100644 --- a/app/combined.php +++ b/bin/combined.php @@ -16,7 +16,6 @@ declare(strict_types=1); use DragonCode\Support\Facades\Filesystem\File; -use LaravelLang\Locales\Enums\Locale; use LaravelLang\NativeLocaleNames\Helpers\Arr; use LaravelLang\NativeLocaleNames\Native; @@ -24,11 +23,13 @@ $result = []; -foreach (Locale::values() as $locale) { +$locales = Arr::file(__DIR__ . '/../source/locales.json'); + +foreach (array_keys($locales) as $locale) { $result[$locale] = Native::get($locale)[$locale]; } File::store( - __DIR__ . '/../locales/_combined/php.json', + __DIR__ . '/../locales/_combined/json.json', json_encode(Arr::ksort($result), JSON_UNESCAPED_UNICODE ^ JSON_UNESCAPED_SLASHES ^ JSON_PRETTY_PRINT) ); diff --git a/composer.json b/composer.json index 21e0466..dd7ab96 100644 --- a/composer.json +++ b/composer.json @@ -31,10 +31,10 @@ "require": { "php": "^8.1", "ext-json": "*", - "dragon-code/support": "^6.11", - "laravel-lang/locales": "^1.0" + "dragon-code/support": "^6.11" }, "require-dev": { + "laravel-lang/locales": "^1.6", "laravel-lang/status-generator": "^2.3.1", "pestphp/pest": "^2.24.3", "symfony/var-dumper": "^6.3" diff --git a/locales/_combined/php.json b/locales/_combined/json.json similarity index 99% rename from locales/_combined/php.json rename to locales/_combined/json.json index 45e0bdb..1cf91e8 100644 --- a/locales/_combined/php.json +++ b/locales/_combined/json.json @@ -78,4 +78,4 @@ "zh_CN": "简体中文)", "zh_HK": "中文(香港)", "zh_TW": "中文(台灣)" -} \ No newline at end of file +} diff --git a/locales/af/php.json b/locales/af/json.json similarity index 100% rename from locales/af/php.json rename to locales/af/json.json diff --git a/locales/ar/php.json b/locales/ar/json.json similarity index 100% rename from locales/ar/php.json rename to locales/ar/json.json diff --git a/locales/az/php.json b/locales/az/json.json similarity index 100% rename from locales/az/php.json rename to locales/az/json.json diff --git a/locales/be/php.json b/locales/be/json.json similarity index 100% rename from locales/be/php.json rename to locales/be/json.json diff --git a/locales/bg/php.json b/locales/bg/json.json similarity index 100% rename from locales/bg/php.json rename to locales/bg/json.json diff --git a/locales/bn/php.json b/locales/bn/json.json similarity index 100% rename from locales/bn/php.json rename to locales/bn/json.json diff --git a/locales/bs/php.json b/locales/bs/json.json similarity index 100% rename from locales/bs/php.json rename to locales/bs/json.json diff --git a/locales/ca/php.json b/locales/ca/json.json similarity index 100% rename from locales/ca/php.json rename to locales/ca/json.json diff --git a/locales/cs/php.json b/locales/cs/json.json similarity index 100% rename from locales/cs/php.json rename to locales/cs/json.json diff --git a/locales/cy/php.json b/locales/cy/json.json similarity index 100% rename from locales/cy/php.json rename to locales/cy/json.json diff --git a/locales/da/php.json b/locales/da/json.json similarity index 100% rename from locales/da/php.json rename to locales/da/json.json diff --git a/locales/de/php.json b/locales/de/json.json similarity index 100% rename from locales/de/php.json rename to locales/de/json.json diff --git a/locales/de_CH/php.json b/locales/de_CH/json.json similarity index 100% rename from locales/de_CH/php.json rename to locales/de_CH/json.json diff --git a/locales/el/php.json b/locales/el/json.json similarity index 100% rename from locales/el/php.json rename to locales/el/json.json diff --git a/locales/en/php.json b/locales/en/json.json similarity index 100% rename from locales/en/php.json rename to locales/en/json.json diff --git a/locales/es/php.json b/locales/es/json.json similarity index 100% rename from locales/es/php.json rename to locales/es/json.json diff --git a/locales/et/php.json b/locales/et/json.json similarity index 100% rename from locales/et/php.json rename to locales/et/json.json diff --git a/locales/eu/php.json b/locales/eu/json.json similarity index 100% rename from locales/eu/php.json rename to locales/eu/json.json diff --git a/locales/fa/php.json b/locales/fa/json.json similarity index 100% rename from locales/fa/php.json rename to locales/fa/json.json diff --git a/locales/fi/php.json b/locales/fi/json.json similarity index 100% rename from locales/fi/php.json rename to locales/fi/json.json diff --git a/locales/fil/php.json b/locales/fil/json.json similarity index 100% rename from locales/fil/php.json rename to locales/fil/json.json diff --git a/locales/fr/php.json b/locales/fr/json.json similarity index 100% rename from locales/fr/php.json rename to locales/fr/json.json diff --git a/locales/gl/php.json b/locales/gl/json.json similarity index 100% rename from locales/gl/php.json rename to locales/gl/json.json diff --git a/locales/gu/php.json b/locales/gu/json.json similarity index 100% rename from locales/gu/php.json rename to locales/gu/json.json diff --git a/locales/he/php.json b/locales/he/json.json similarity index 100% rename from locales/he/php.json rename to locales/he/json.json diff --git a/locales/hi/php.json b/locales/hi/json.json similarity index 100% rename from locales/hi/php.json rename to locales/hi/json.json diff --git a/locales/hr/php.json b/locales/hr/json.json similarity index 100% rename from locales/hr/php.json rename to locales/hr/json.json diff --git a/locales/hu/php.json b/locales/hu/json.json similarity index 100% rename from locales/hu/php.json rename to locales/hu/json.json diff --git a/locales/hy/php.json b/locales/hy/json.json similarity index 100% rename from locales/hy/php.json rename to locales/hy/json.json diff --git a/locales/id/php.json b/locales/id/json.json similarity index 100% rename from locales/id/php.json rename to locales/id/json.json diff --git a/locales/is/php.json b/locales/is/json.json similarity index 100% rename from locales/is/php.json rename to locales/is/json.json diff --git a/locales/it/php.json b/locales/it/json.json similarity index 100% rename from locales/it/php.json rename to locales/it/json.json diff --git a/locales/ja/php.json b/locales/ja/json.json similarity index 100% rename from locales/ja/php.json rename to locales/ja/json.json diff --git a/locales/ka/php.json b/locales/ka/json.json similarity index 100% rename from locales/ka/php.json rename to locales/ka/json.json diff --git a/locales/kk/php.json b/locales/kk/json.json similarity index 100% rename from locales/kk/php.json rename to locales/kk/json.json diff --git a/locales/km/php.json b/locales/km/json.json similarity index 100% rename from locales/km/php.json rename to locales/km/json.json diff --git a/locales/kn/php.json b/locales/kn/json.json similarity index 100% rename from locales/kn/php.json rename to locales/kn/json.json diff --git a/locales/ko/php.json b/locales/ko/json.json similarity index 100% rename from locales/ko/php.json rename to locales/ko/json.json diff --git a/locales/lt/php.json b/locales/lt/json.json similarity index 100% rename from locales/lt/php.json rename to locales/lt/json.json diff --git a/locales/lv/php.json b/locales/lv/json.json similarity index 100% rename from locales/lv/php.json rename to locales/lv/json.json diff --git a/locales/mk/php.json b/locales/mk/json.json similarity index 100% rename from locales/mk/php.json rename to locales/mk/json.json diff --git a/locales/mn/php.json b/locales/mn/json.json similarity index 100% rename from locales/mn/php.json rename to locales/mn/json.json diff --git a/locales/mr/php.json b/locales/mr/json.json similarity index 100% rename from locales/mr/php.json rename to locales/mr/json.json diff --git a/locales/ms/php.json b/locales/ms/json.json similarity index 100% rename from locales/ms/php.json rename to locales/ms/json.json diff --git a/locales/nb/php.json b/locales/nb/json.json similarity index 100% rename from locales/nb/php.json rename to locales/nb/json.json diff --git a/locales/ne/php.json b/locales/ne/json.json similarity index 100% rename from locales/ne/php.json rename to locales/ne/json.json diff --git a/locales/nl/php.json b/locales/nl/json.json similarity index 100% rename from locales/nl/php.json rename to locales/nl/json.json diff --git a/locales/nn/php.json b/locales/nn/json.json similarity index 100% rename from locales/nn/php.json rename to locales/nn/json.json diff --git a/locales/oc/php.json b/locales/oc/json.json similarity index 100% rename from locales/oc/php.json rename to locales/oc/json.json diff --git a/locales/pl/php.json b/locales/pl/json.json similarity index 100% rename from locales/pl/php.json rename to locales/pl/json.json diff --git a/locales/ps/php.json b/locales/ps/json.json similarity index 100% rename from locales/ps/php.json rename to locales/ps/json.json diff --git a/locales/pt/php.json b/locales/pt/json.json similarity index 100% rename from locales/pt/php.json rename to locales/pt/json.json diff --git a/locales/pt_BR/php.json b/locales/pt_BR/json.json similarity index 100% rename from locales/pt_BR/php.json rename to locales/pt_BR/json.json diff --git a/locales/ro/php.json b/locales/ro/json.json similarity index 100% rename from locales/ro/php.json rename to locales/ro/json.json diff --git a/locales/ru/php.json b/locales/ru/json.json similarity index 100% rename from locales/ru/php.json rename to locales/ru/json.json diff --git a/locales/sc/php.json b/locales/sc/json.json similarity index 100% rename from locales/sc/php.json rename to locales/sc/json.json diff --git a/locales/si/php.json b/locales/si/json.json similarity index 100% rename from locales/si/php.json rename to locales/si/json.json diff --git a/locales/sk/php.json b/locales/sk/json.json similarity index 100% rename from locales/sk/php.json rename to locales/sk/json.json diff --git a/locales/sl/php.json b/locales/sl/json.json similarity index 100% rename from locales/sl/php.json rename to locales/sl/json.json diff --git a/locales/sq/php.json b/locales/sq/json.json similarity index 100% rename from locales/sq/php.json rename to locales/sq/json.json diff --git a/locales/sr_Cyrl/php.json b/locales/sr_Cyrl/json.json similarity index 100% rename from locales/sr_Cyrl/php.json rename to locales/sr_Cyrl/json.json diff --git a/locales/sr_Latn/php.json b/locales/sr_Latn/json.json similarity index 100% rename from locales/sr_Latn/php.json rename to locales/sr_Latn/json.json diff --git a/locales/sr_Latn_ME/php.json b/locales/sr_Latn_ME/json.json similarity index 100% rename from locales/sr_Latn_ME/php.json rename to locales/sr_Latn_ME/json.json diff --git a/locales/sv/php.json b/locales/sv/json.json similarity index 100% rename from locales/sv/php.json rename to locales/sv/json.json diff --git a/locales/sw/php.json b/locales/sw/json.json similarity index 100% rename from locales/sw/php.json rename to locales/sw/json.json diff --git a/locales/tg/php.json b/locales/tg/json.json similarity index 100% rename from locales/tg/php.json rename to locales/tg/json.json diff --git a/locales/th/php.json b/locales/th/json.json similarity index 100% rename from locales/th/php.json rename to locales/th/json.json diff --git a/locales/tk/php.json b/locales/tk/json.json similarity index 100% rename from locales/tk/php.json rename to locales/tk/json.json diff --git a/locales/tl/php.json b/locales/tl/json.json similarity index 100% rename from locales/tl/php.json rename to locales/tl/json.json diff --git a/locales/tr/php.json b/locales/tr/json.json similarity index 100% rename from locales/tr/php.json rename to locales/tr/json.json diff --git a/locales/ug/php.json b/locales/ug/json.json similarity index 100% rename from locales/ug/php.json rename to locales/ug/json.json diff --git a/locales/uk/php.json b/locales/uk/json.json similarity index 100% rename from locales/uk/php.json rename to locales/uk/json.json diff --git a/locales/ur/php.json b/locales/ur/json.json similarity index 100% rename from locales/ur/php.json rename to locales/ur/json.json diff --git a/locales/uz_Cyrl/php.json b/locales/uz_Cyrl/json.json similarity index 100% rename from locales/uz_Cyrl/php.json rename to locales/uz_Cyrl/json.json diff --git a/locales/uz_Latn/php.json b/locales/uz_Latn/json.json similarity index 100% rename from locales/uz_Latn/php.json rename to locales/uz_Latn/json.json diff --git a/locales/vi/php.json b/locales/vi/json.json similarity index 100% rename from locales/vi/php.json rename to locales/vi/json.json diff --git a/locales/zh_CN/php.json b/locales/zh_CN/json.json similarity index 100% rename from locales/zh_CN/php.json rename to locales/zh_CN/json.json diff --git a/locales/zh_HK/php.json b/locales/zh_HK/json.json similarity index 100% rename from locales/zh_HK/php.json rename to locales/zh_HK/json.json diff --git a/locales/zh_TW/php.json b/locales/zh_TW/json.json similarity index 100% rename from locales/zh_TW/php.json rename to locales/zh_TW/json.json diff --git a/source/locales.json b/source/locales.json new file mode 100644 index 0000000..0ac41e6 --- /dev/null +++ b/source/locales.json @@ -0,0 +1,81 @@ +{ + "af": "Afrikaans", + "ar": "Arabic", + "az": "Azerbaijani (Latin)", + "be": "Belarusian", + "bg": "Bulgarian", + "bn": "Bengali", + "bs": "Bosnian", + "ca": "Catalan", + "cs": "Czech", + "cy": "Welsh", + "da": "Danish", + "de": "German", + "de_CH": "Swiss High German", + "el": "Greek", + "en": "English", + "es": "Spanish", + "et": "Estonian", + "eu": "Basque", + "fa": "Persian", + "fi": "Finnish", + "fil": "Filipino", + "fr": "French", + "gl": "Galician", + "gu": "Gujarati", + "he": "Hebrew", + "hi": "Hindi", + "hr": "Croatian", + "hu": "Hungarian", + "hy": "Armenian", + "id": "Indonesian", + "is": "Icelandic", + "it": "Italian", + "ja": "Japanese", + "ka": "Georgian", + "kk": "Kazakh", + "km": "Khmer", + "kn": "Kannada", + "ko": "Korean", + "lt": "Lithuanian", + "lv": "Latvian", + "mk": "Macedonian", + "mn": "Mongolian", + "mr": "Marathi", + "ms": "Malay", + "nb": "Norwegian Bokmål", + "ne": "Nepali", + "nl": "Dutch", + "nn": "Norwegian Nynorsk", + "oc": "Occitan", + "pl": "Polish", + "ps": "Pashto", + "pt": "Portuguese", + "pt_BR": "Brazilian Portuguese", + "ro": "Romanian", + "ru": "Russian", + "sc": "Sardinian", + "si": "Sinhala", + "sk": "Slovak", + "sl": "Slovene", + "sq": "Albanian", + "sr_Cyrl": "Serbian (Cyrillic)", + "sr_Latn": "Serbian (Latin)", + "sr_Latn_ME": "Serbian (Montenegro)", + "sv": "Swedish", + "sw": "Swahili", + "tg": "Tajik (Cyrillic)", + "th": "Thai", + "tk": "Turkmen", + "tl": "Tagalog", + "tr": "Turkish", + "ug": "Uyghur", + "uk": "Ukrainian", + "ur": "Urdu", + "uz_Cyrl": "Uzbek (Cyrillic)", + "uz_Latn": "Uzbek (Latin)", + "vi": "Vietnamese", + "zh_CN": "Chinese (Simplified)", + "zh_HK": "Chinese (Hong Kong)", + "zh_TW": "Chinese (Taiwan)" +} diff --git a/source/locales.php b/source/locales.php deleted file mode 100644 index a901da8..0000000 --- a/source/locales.php +++ /dev/null @@ -1,100 +0,0 @@ - - * @copyright 2023 Laravel Lang Team - * @license MIT - * - * @see https://laravel-lang.com - */ - -declare(strict_types=1); - -use LaravelLang\Locales\Enums\Locale; - -return [ - Locale::Afrikaans->value => 'Afrikaans', - Locale::Albanian->value => 'Albanian', - Locale::Arabic->value => 'Arabic', - Locale::Armenian->value => 'Armenian', - Locale::Azerbaijani->value => 'Azerbaijani (Latin)', - Locale::Basque->value => 'Basque', - Locale::Belarusian->value => 'Belarusian', - Locale::Bengali->value => 'Bengali', - Locale::Bosnian->value => 'Bosnian', - Locale::Bulgarian->value => 'Bulgarian', - Locale::Catalan->value => 'Catalan', - Locale::CentralKhmer->value => 'Khmer', - Locale::Chinese->value => 'Chinese (Simplified)', - Locale::ChineseHongKong->value => 'Chinese (Hong Kong)', - Locale::ChineseT->value => 'Chinese (Taiwan)', - Locale::Croatian->value => 'Croatian', - Locale::Czech->value => 'Czech', - Locale::Danish->value => 'Danish', - Locale::Dutch->value => 'Dutch', - Locale::English->value => 'English', - Locale::Estonian->value => 'Estonian', - Locale::Finnish->value => 'Finnish', - Locale::French->value => 'French', - Locale::Galician->value => 'Galician', - Locale::Georgian->value => 'Georgian', - Locale::German->value => 'German', - Locale::GermanSwitzerland->value => 'Swiss High German', - Locale::Greek->value => 'Greek', - Locale::Gujarati->value => 'Gujarati', - Locale::Hebrew->value => 'Hebrew', - Locale::Hindi->value => 'Hindi', - Locale::Hungarian->value => 'Hungarian', - Locale::Icelandic->value => 'Icelandic', - Locale::Indonesian->value => 'Indonesian', - Locale::Italian->value => 'Italian', - Locale::Japanese->value => 'Japanese', - Locale::Kannada->value => 'Kannada', - Locale::Kazakh->value => 'Kazakh', - Locale::Korean->value => 'Korean', - Locale::Latvian->value => 'Latvian', - Locale::Lithuanian->value => 'Lithuanian', - Locale::Macedonian->value => 'Macedonian', - Locale::Malay->value => 'Malay', - Locale::Marathi->value => 'Marathi', - Locale::Mongolian->value => 'Mongolian', - Locale::Nepali->value => 'Nepali', - Locale::NorwegianBokmal->value => 'Norwegian Bokmål', - Locale::NorwegianNynorsk->value => 'Norwegian Nynorsk', - Locale::Occitan->value => 'Occitan', - Locale::Pashto->value => 'Pashto', - Locale::Persian->value => 'Persian', - Locale::Pilipino->value => 'Filipino', - Locale::Polish->value => 'Polish', - Locale::Portuguese->value => 'Portuguese', - Locale::PortugueseBrazil->value => 'Brazilian Portuguese', - Locale::Romanian->value => 'Romanian', - Locale::Russian->value => 'Russian', - Locale::Sardinian->value => 'Sardinian', - Locale::SerbianCyrillic->value => 'Serbian (Cyrillic)', - Locale::SerbianLatin->value => 'Serbian (Latin)', - Locale::SerbianMontenegrin->value => 'Serbian (Montenegro)', - Locale::Sinhala->value => 'Sinhala', - Locale::Slovak->value => 'Slovak', - Locale::Slovenian->value => 'Slovene', - Locale::Spanish->value => 'Spanish', - Locale::Swahili->value => 'Swahili', - Locale::Swedish->value => 'Swedish', - Locale::Tagalog->value => 'Tagalog', - Locale::Tajik->value => 'Tajik (Cyrillic)', - Locale::Thai->value => 'Thai', - Locale::Turkish->value => 'Turkish', - Locale::Turkmen->value => 'Turkmen', - Locale::Uighur->value => 'Uyghur', - Locale::Ukrainian->value => 'Ukrainian', - Locale::Urdu->value => 'Urdu', - Locale::UzbekCyrillic->value => 'Uzbek (Cyrillic)', - Locale::UzbekLatin->value => 'Uzbek (Latin)', - Locale::Vietnamese->value => 'Vietnamese', - Locale::Welsh->value => 'Welsh', -]; diff --git a/src/Helpers/Path.php b/src/Helpers/Path.php index 176fef0..61ba655 100644 --- a/src/Helpers/Path.php +++ b/src/Helpers/Path.php @@ -21,6 +21,11 @@ class Path { public static function resolve(string $locale): bool|string { - return realpath(__DIR__ . '/../../locales/' . $locale . '/php.json'); + return realpath(__DIR__ . '/../../locales/' . $locale . '/json.json'); + } + + public static function exists(string $locale): bool + { + return static::resolve($locale) !== false; } } diff --git a/src/Native.php b/src/Native.php index 9e2c4de..9c98959 100644 --- a/src/Native.php +++ b/src/Native.php @@ -56,6 +56,10 @@ protected static function locale(Locale|string|null $locale): ?string return null; } - return $locale->value ?? Locale::tryFrom($locale)?->value; + if (class_exists(Locale::class) && $locale instanceof Locale) { + return $locale->value; + } + + return Path::exists($locale) ? $locale : null; } } diff --git a/tests/Helpers/native.php b/tests/Helpers/native.php index 0e6ddcc..ac90f46 100644 --- a/tests/Helpers/native.php +++ b/tests/Helpers/native.php @@ -19,5 +19,5 @@ function sourceLocale(string $locale): array { - return Arr::file(__DIR__ . '/../../locales/' . $locale . '/php.json'); + return Arr::file(__DIR__ . '/../../locales/' . $locale . '/json.json'); }