Skip to content

Commit

Permalink
Language code improvements (#150)
Browse files Browse the repository at this point in the history
* Language code improvements (#147)

* improved language code handling

* expanded skipping behaviour

* remove unused code

* Added an option to detect language with whisper before choosing to skip it

---------

Co-authored-by: muisje <[email protected]>

* Default LanguageCode inputs to from_string and fix detect_langauge

* Skip detect-language if we have forced a detected language

* Typecast user inputs to ints as appropriate.

* Update subgen.py

* Update subgen.py

* Update subgen.py

---------

Co-authored-by: muisje <[email protected]>
  • Loading branch information
McCloudS and muisje authored Dec 4, 2024
1 parent 66dc8e5 commit d840c40
Show file tree
Hide file tree
Showing 2 changed files with 329 additions and 76 deletions.
14 changes: 10 additions & 4 deletions language_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class LanguageCode(Enum):
YORUBA = ("yo", "yor", "yor", "Yoruba", "Yorùbá")
CHINESE = ("zh", "zho", "chi", "Chinese", "中文")
CANTONESE = ("yue", "yue", "yue", "Cantonese", "粵語")
NONE = (None, None, None, None, None) # For unknown languages or no language
NONE = (None, None, None, None, None) # For no language
# und for Undetermined aka unknown language https://www.loc.gov/standards/iso639-2/faq.html#25

def __init__(self, iso_639_1, iso_639_2_t, iso_639_2_b, name_en, name_native):
self.iso_639_1 = iso_639_1
Expand Down Expand Up @@ -155,6 +156,11 @@ def from_string(value: str):
return lang
return LanguageCode.NONE

# is valid language
@staticmethod
def is_valid_language(language: str):
return LanguageCode.from_string(language) is not LanguageCode.NONE

def to_iso_639_1(self):
return self.iso_639_1

Expand All @@ -180,10 +186,10 @@ def __eq__(self, other):
Explicitly handle comparison to None.
"""
if other is None:
# If compared to None, return False
# print(other)
# print(self)
# If compared to None, return False unless self is None
return self.iso_639_1 is None
if isinstance(other, str): # Allow comparison with a string
return self.value == LanguageCode.from_string(other)
if isinstance(other, LanguageCode):
# Normal comparison for LanguageCode instances
return self.iso_639_1 == other.iso_639_1
Expand Down
Loading

0 comments on commit d840c40

Please sign in to comment.