MCPcopy Index your code
hub / github.com/McCloudS/subgen / from_string

Method from_string

language_code.py:143–161  ·  view source on GitHub ↗

Convert a string to a LanguageCode instance. Matches on ISO codes, English name, or native name.

(value: str)

Source from the content-addressed store, hash-verified

141
142 @staticmethod
143 def from_string(value: str):
144 """
145 Convert a string to a LanguageCode instance. Matches on ISO codes, English name, or native name.
146 """
147 if value is None:
148 return LanguageCode.NONE
149 value = value.strip().lower()
150 for lang in LanguageCode:
151 if lang is LanguageCode.NONE:
152 continue
153 elif (
154 value == lang.iso_639_1
155 or value == lang.iso_639_2_t
156 or value == lang.iso_639_2_b
157 or value == lang.name_en.lower()
158 or value == lang.name_native.lower()
159 ):
160 return lang
161 return LanguageCode.NONE
162
163 # is valid language
164 @staticmethod

Callers 15

subgen.pyFile · 0.80
batchFunction · 0.80
detect_languageFunction · 0.80
detect_language_taskFunction · 0.80
gen_subtitlesFunction · 0.80
should_skip_fileFunction · 0.80
is_valid_languageMethod · 0.80
__eq__Method · 0.80
test_iso_639_1Method · 0.80

Calls

no outgoing calls

Tested by 12

test_iso_639_1Method · 0.64
test_iso_639_2Method · 0.64
test_english_nameMethod · 0.64
test_native_nameMethod · 0.64
test_none_inputMethod · 0.64
test_empty_stringMethod · 0.64
test_invalid_codeMethod · 0.64
test_frenchMethod · 0.64