128 """Fetch languages and countrycodes from RadioBrowser
130 - ``traits.languages``: `list of languages API`_
131 - ``traits.custom['countrycodes']``: `list of countries API`_
133 .. _list of countries API: https://de1.api.radio-browser.info/#List_of_countries
134 .. _list of languages API: https://de1.api.radio-browser.info/#List_of_languages
138 from babel.core
import get_global
140 babel_reg_list = get_global(
"territory_languages").keys()
142 language_list = get(f
'{base_url}/json/languages').json()
143 country_list = get(f
'{base_url}/json/countries').json()
145 for lang
in language_list:
147 babel_lang = lang.get(
'iso_639')
153 sxng_tag = language_tag(babel.Locale.parse(babel_lang, sep=
"-"))
154 except babel.UnknownLocaleError:
158 eng_tag = lang[
'name']
159 conflict = engine_traits.languages.get(sxng_tag)
161 if conflict != eng_tag:
162 print(
"CONFLICT: babel %s --> %s, %s" % (sxng_tag, conflict, eng_tag))
164 engine_traits.languages[sxng_tag] = eng_tag
167 for region
in country_list:
169 _reg = region[
'iso_3166_1'].upper()
170 if _reg
not in babel_reg_list:
171 print(f
"ERROR: region tag {region['iso_3166_1']} is unknown by babel")
173 countrycodes.add(_reg)
175 countrycodes = list(countrycodes)
177 engine_traits.custom[
'countrycodes'] = countrycodes