-
-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Subtitulamos provider integration (#1170)
* feat: Add Subtitulamos provider integration * chore: Add Subtitulamos provider integration - Add changelog * chore: Add Subtitulamos provider integration - Improve 'Español (Latinoamérica)' support adding all countries --------- Co-authored-by: getzze <getzze@gmail.com>
- Loading branch information
Showing
19 changed files
with
14,657 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added Subtitulamos provider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"""Language converter for Subtitulamos.""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from babelfish import LanguageReverseConverter, language_converters # type: ignore[import-untyped] | ||
|
||
if TYPE_CHECKING: | ||
from . import LanguageTuple | ||
|
||
|
||
class SubtitulamosConverter(LanguageReverseConverter): | ||
"""Language converter for Subtitulamos.""" | ||
|
||
def __init__(self) -> None: | ||
self.name_converter = language_converters['name'] | ||
self.from_subtitulamos: dict[str, tuple[str, str | None]] = { | ||
'Español': ('spa', None), | ||
'Español (España)': ('spa', None), | ||
'Español (Latinoamérica)': ('spa', 'MX'), | ||
'Català': ('cat', None), | ||
'English': ('eng', None), | ||
'Galego': ('glg', None), | ||
'Portuguese': ('por', None), | ||
'English (US)': ('eng', 'US'), | ||
'English (UK)': ('eng', 'GB'), | ||
'Brazilian': ('por', 'BR'), | ||
} | ||
self.to_subtitulamos: dict[tuple[str, str | None], str] = { | ||
item[1]: item[0] for item in self.from_subtitulamos.items() | ||
} | { | ||
('spa', country): 'Español (Latinoamérica)' | ||
for country in [ | ||
'AR', # Argentina | ||
'BO', # Bolivia | ||
'CL', # Chile | ||
'CO', # Colombia | ||
'CR', # Costa Rica | ||
'DO', # República Dominicana | ||
'EC', # Ecuador | ||
'GT', # Guatemala | ||
'HN', # Honduras | ||
'NI', # Nicaragua | ||
'PA', # Panamá | ||
'PE', # Perú | ||
'PR', # Puerto Rico | ||
'PY', # Paraguay | ||
'SV', # El Salvador | ||
'US', # United States | ||
'UY', # Uruguay | ||
'VE', # Venezuela | ||
] | ||
} | ||
self.codes = set(self.from_subtitulamos.keys()) | ||
|
||
def convert(self, alpha3: str, country: str | None = None, script: str | None = None) -> str: | ||
"""Convert an alpha3 language code with an alpha2 country code and a script code into a custom code.""" | ||
if (alpha3, country) in self.to_subtitulamos: | ||
return self.to_subtitulamos[(alpha3, country)] | ||
|
||
return self.name_converter.convert(alpha3, country, script) # type: ignore[no-any-return] | ||
|
||
def reverse(self, code: str) -> LanguageTuple: | ||
"""Reverse a custom code into alpha3, country and script code.""" | ||
if code in self.from_subtitulamos: | ||
return (*self.from_subtitulamos[code], None) | ||
|
||
return self.name_converter.reverse(code) # type: ignore[no-any-return] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.