From 4482375ec70b33328c6d9096f2a5712aef67be1b Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 27 Jun 2024 01:54:29 +0300 Subject: [PATCH] Added list of supported localizations for Google and Deepl --- src/Integrations/Deepl.php | 88 ++++++++++++++++++++- src/Integrations/Google.php | 132 ++++++++++++++++++++++++++++++- src/Integrations/Integration.php | 4 +- src/Integrations/Yandex.php | 4 +- src/ServiceProvider.php | 2 +- tests/Helpers/Mocks.php | 2 +- 6 files changed, 219 insertions(+), 13 deletions(-) diff --git a/src/Integrations/Deepl.php b/src/Integrations/Deepl.php index bd750c8..45faf25 100644 --- a/src/Integrations/Deepl.php +++ b/src/Integrations/Deepl.php @@ -10,12 +10,94 @@ class Deepl extends Integration { - public static string $integration = DeeplTranslator::class; - + /** + * @see https://www.deepl.com/ru/translator + * + * @var array + */ protected array $map = [ - Locale::French->value => 'fr', + // Locale::Afrikaans->value => 'af', + // Locale::Albanian->value => 'sq', + // Locale::Arabic->value => 'ar', + // Locale::Armenian->value => 'hy', + // Locale::Azerbaijani->value => 'az', + // Locale::Basque->value => 'eu', + // Locale::Belarusian->value => 'be', + // Locale::Bengali->value => 'bn', + // Locale::Bosnian->value => 'bs', + Locale::Bulgarian->value => 'bg', + // Locale::Catalan->value => 'ca', + // Locale::CentralKhmer->value => 'km', + // Locale::Chinese->value => 'zh-CN', + Locale::ChineseHongKong->value => 'zh', + // Locale::ChineseT->value => 'zh-TW', + // Locale::Croatian->value => 'hr', + Locale::Czech->value => 'cs', + Locale::Danish->value => 'da', + Locale::Dutch->value => 'nl', + Locale::Estonian->value => 'et', + Locale::Finnish->value => 'fi', + Locale::French->value => 'fr', + // Locale::Galician->value => 'gl', + // Locale::Georgian->value => 'ka', + Locale::German->value => 'de', + Locale::GermanSwitzerland->value => 'de', + Locale::Greek->value => 'el', + // Locale::Gujarati->value => 'gu', + // Locale::Hebrew->value => 'he', + // Locale::Hindi->value => 'hi', + Locale::Hungarian->value => 'hu', + // Locale::Icelandic->value => 'is', + Locale::Indonesian->value => 'id', + Locale::Italian->value => 'it', + Locale::Japanese->value => 'ja', + // Locale::Kannada->value => 'kn', + // Locale::Kazakh->value => 'kk', + Locale::Korean->value => 'ko', + Locale::Latvian->value => 'lv', + Locale::Lithuanian->value => 'lt', + // Locale::Macedonian->value => 'mk', + // Locale::Malay->value => 'ms', + // Locale::Marathi->value => 'mr', + // Locale::Mongolian->value => 'mn', + // Locale::Nepali->value => 'ne', + Locale::NorwegianBokmal->value => 'no', + Locale::NorwegianNynorsk->value => 'no', + // Locale::Occitan->value => 'oc', + // Locale::Pashto->value => 'ps', + // Locale::Persian->value => 'fa', + // Locale::Pilipino->value => 'fil', + Locale::Polish->value => 'pl', + Locale::Portuguese->value => 'pt', + Locale::PortugueseBrazil->value => 'pt-BR', + Locale::Romanian->value => 'ro', + Locale::Russian->value => 'ru', + // Locale::Sardinian->value => 'sc', + // Locale::SerbianCyrillic->value => 'sr', + // Locale::SerbianLatin->value => 'sr-Latn', + // Locale::SerbianMontenegrin->value => 'sr-Latn-ME', + // Locale::Sinhala->value => 'si', + Locale::Slovak->value => 'sk', + Locale::Slovenian->value => 'sl', + Locale::Spanish->value => 'es', + // Locale::Swahili->value => 'sw', + Locale::Swedish->value => 'sv', + // Locale::Tagalog->value => 'tl', + // Locale::Tajik->value => 'tg', + // Locale::Thai->value => 'th', + Locale::Turkish->value => 'tr', + // Locale::Turkmen->value => 'tk', + // Locale::Uighur->value => 'ug', + Locale::Ukrainian->value => 'uk', + // Locale::Urdu->value => 'ur', + // Locale::UzbekCyrillic->value => 'uz', + // Locale::UzbekLatin->value => 'uz-Latn', + // Locale::Vietnamese->value => 'vi', + // Locale::Welsh->value => 'cy', ]; + public static string $integration = DeeplTranslator::class; + public function __construct( protected DeeplTranslator $translator ) {} diff --git a/src/Integrations/Google.php b/src/Integrations/Google.php index 312b516..c96f97e 100644 --- a/src/Integrations/Google.php +++ b/src/Integrations/Google.php @@ -10,15 +10,139 @@ class Google extends Integration { - public static string $integration = GoogleTranslate::class; - + /** + * @see https://cloud.google.com/translate/docs/languages + * + * @var array + */ protected array $map = [ - Locale::French->value => 'fr', + Locale::Afrikaans->value => 'af', + Locale::Albanian->value => 'sq', + Locale::Amharic->value => 'am', + Locale::Arabic->value => 'ar', + Locale::Armenian->value => 'hy', + Locale::Assamese->value => 'as', + Locale::Azerbaijani->value => 'az', + Locale::Bambara->value => 'bm', + Locale::Basque->value => 'eu', + Locale::Belarusian->value => 'be', + Locale::Bengali->value => 'bn', + Locale::Bhojpuri->value => 'bho', + Locale::Bosnian->value => 'bs', + Locale::Bulgarian->value => 'bg', + Locale::Catalan->value => 'ca', + Locale::Cebuano->value => 'ceb', + Locale::CentralKhmer->value => 'km', + Locale::Chinese->value => 'zh-CN', + Locale::ChineseHongKong->value => 'zh', + Locale::ChineseT->value => 'zh-TW', + Locale::Croatian->value => 'hr', + Locale::Czech->value => 'cs', + Locale::Danish->value => 'da', + Locale::Dogri->value => 'doi', + Locale::Dutch->value => 'nl', + Locale::Esperanto->value => 'eo', + Locale::Estonian->value => 'et', + Locale::Ewe->value => 'ee', + Locale::Finnish->value => 'fi', + Locale::French->value => 'fr', + Locale::Frisian->value => 'fy', + Locale::Galician->value => 'gl', + Locale::Georgian->value => 'ka', + Locale::German->value => 'de', + Locale::GermanSwitzerland->value => 'de', + Locale::Greek->value => 'el', + Locale::Gujarati->value => 'gu', + Locale::Hausa->value => 'ha', + Locale::Hawaiian->value => 'haw', + Locale::Hebrew->value => 'he', + Locale::Hindi->value => 'hi', + Locale::Hungarian->value => 'hu', + Locale::Icelandic->value => 'is', + Locale::Igbo->value => 'ig', + Locale::Indonesian->value => 'id', + Locale::Irish->value => 'ga', + Locale::Italian->value => 'it', + Locale::Japanese->value => 'ja', + Locale::Kannada->value => 'kn', + Locale::Kazakh->value => 'kk', + Locale::Kinyarwanda->value => 'rw', + Locale::Korean->value => 'ko', + Locale::Kurdish->value => 'ku', + Locale::KurdishSorani->value => 'ckb', + Locale::Kyrgyz->value => 'ky', + Locale::Lao->value => 'lo', + Locale::Latvian->value => 'lv', + Locale::Lingala->value => 'ln', + Locale::Lithuanian->value => 'lt', + Locale::Luganda->value => 'lg', + Locale::Luxembourgish->value => 'lb', + Locale::Macedonian->value => 'mk', + Locale::Maithili->value => 'mai', + Locale::Malagasy->value => 'mg', + Locale::Malay->value => 'ms', + Locale::Malayalam->value => 'ml', + Locale::Maltese->value => 'mt', + Locale::Maori->value => 'mi', + Locale::Marathi->value => 'mr', + Locale::MeiteilonManipuri->value => 'mni-Mtei', + Locale::Mongolian->value => 'mn', + Locale::MyanmarBurmese->value => 'my', + Locale::Nepali->value => 'ne', + Locale::NorwegianBokmal->value => 'no', + Locale::NorwegianNynorsk->value => 'no', + Locale::OdiaOriya->value => 'or', + Locale::Oromo->value => 'om', + Locale::Pashto->value => 'ps', + Locale::Persian->value => 'fa', + Locale::Pilipino->value => 'fil', + Locale::Polish->value => 'pl', + Locale::Portuguese->value => 'pt', + Locale::PortugueseBrazil->value => 'pt', + Locale::Punjabi->value => 'pa', + Locale::Quechua->value => 'qu', + Locale::Romanian->value => 'ro', + Locale::Russian->value => 'ru', + Locale::Sanskrit->value => 'sa', + Locale::ScotsGaelic->value => 'gd', + Locale::SerbianCyrillic->value => 'sr', + Locale::Shona->value => 'sn', + Locale::Sindhi->value => 'sd', + Locale::Sinhala->value => 'si', + Locale::Slovak->value => 'sk', + Locale::Slovenian->value => 'sl', + Locale::Somali->value => 'so', + Locale::Spanish->value => 'es', + Locale::Sundanese->value => 'su', + Locale::Swahili->value => 'sw', + Locale::Swedish->value => 'sv', + Locale::Tagalog->value => 'tl', + Locale::Tajik->value => 'tg', + Locale::Tamil->value => 'ta', + Locale::Tatar->value => 'tt', + Locale::Telugu->value => 'te', + Locale::Thai->value => 'th', + Locale::Tigrinya->value => 'ti', + Locale::Turkish->value => 'tr', + Locale::Turkmen->value => 'tk', + Locale::TwiAkan->value => 'ak', + Locale::Uighur->value => 'ug', + Locale::Ukrainian->value => 'uk', + Locale::Urdu->value => 'ur', + Locale::UzbekCyrillic->value => 'uz', + Locale::Vietnamese->value => 'vi', + Locale::Welsh->value => 'cy', + Locale::Xhosa->value => 'xh', + Locale::Yiddish->value => 'yi', + Locale::Yoruba->value => 'yo', + Locale::Zulu->value => 'zu', ]; + public static string $integration = GoogleTranslate::class; + public function __construct( protected GoogleTranslate $translator, - protected string|bool $regex = true + protected bool|string $regex = true ) {} protected function request(iterable|string $text, Locale|string $to, Locale|string|null $from): Collection diff --git a/src/Integrations/Integration.php b/src/Integrations/Integration.php index 132c100..6ef2845 100644 --- a/src/Integrations/Integration.php +++ b/src/Integrations/Integration.php @@ -10,10 +10,10 @@ abstract class Integration implements Translator { - public static string $integration; - protected array $map = []; + public static string $integration; + abstract protected function request( iterable|string $text, Locale|string $to, diff --git a/src/Integrations/Yandex.php b/src/Integrations/Yandex.php index 5e942e3..6af61ce 100644 --- a/src/Integrations/Yandex.php +++ b/src/Integrations/Yandex.php @@ -10,12 +10,12 @@ class Yandex extends Integration { - public static string $integration = YandexCloud::class; - protected array $map = [ Locale::French->value => 'fr', ]; + public static string $integration = YandexCloud::class; + public function __construct( protected YandexCloud $translator, ) {} diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 849540c..04ba707 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -18,7 +18,7 @@ public function boot(): void } } - protected function bootTranslator(Translator|string $translator, array $credentials): void + protected function bootTranslator(string|Translator $translator, array $credentials): void { $this->app->singleton($translator, fn () => new $translator( new $translator::$integration(...$credentials) diff --git a/tests/Helpers/Mocks.php b/tests/Helpers/Mocks.php index 6bae72c..f58d430 100644 --- a/tests/Helpers/Mocks.php +++ b/tests/Helpers/Mocks.php @@ -11,7 +11,7 @@ use Stichoza\GoogleTranslate\GoogleTranslate; use Tests\Constants\Value; -function mockTranslators(array|string $text = null): void +function mockTranslators(array|string|null $text = null): void { mockDeeplTranslator($text); mockGoogleTranslator($text);