Skip to content

Commit

Permalink
Added list of supported localizations for Google and Deepl
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-helldar committed Jun 26, 2024
1 parent bf46b12 commit 4482375
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 13 deletions.
88 changes: 85 additions & 3 deletions src/Integrations/Deepl.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,94 @@

class Deepl extends Integration
{
public static string $integration = DeeplTranslator::class;

/**
* @see https://www.deepl.com/ru/translator
*
* @var array<string>
*/
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
) {}
Expand Down
132 changes: 128 additions & 4 deletions src/Integrations/Google.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,139 @@

class Google extends Integration
{
public static string $integration = GoogleTranslate::class;

/**
* @see https://cloud.google.com/translate/docs/languages
*
* @var array<string>
*/
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
Expand Down
4 changes: 2 additions & 2 deletions src/Integrations/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/Integrations/Yandex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {}
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/Helpers/Mocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4482375

Please sign in to comment.