def best_lang_old(self, locale_codes):
# based on a simple ordered list of locale_codes
locale_collection = Locale.locale_collection
locale_collection_subsets = Locale.locale_collection_subsets
available = self.entries_as_dict
if len(available) == 0:
return LangStringEntry.EMPTY()
if len(available) == 1:
# optimize for common case
return available[0]
for locale_code in locale_codes:
# is the locale there?
if locale_code in available:
return available[locale_code]
# is the base locale there?
root_locale = Locale.extract_root_locale(locale_code)
if root_locale not in locale_codes:
locale_id = locale_collection.get(root_locale, None)
if locale_id and locale_id in available:
return available[locale_id]
# is another variant there?
mt_variants = list()
for sublocale in locale_collection_subsets[root_locale]:
if sublocale in locale_codes:
continue
if sublocale == root_locale:
continue
if Locale.locale_is_machine_translated(sublocale):
mt_variants.append(sublocale)
continue
locale_id = locale_collection.get(sublocale, None)
if locale_id and locale_id in available:
return available
# We found nothing, look at MT variants.
for sublocale in mt_variants:
locale_id = locale_collection.get(sublocale, None)
if locale_id and locale_id in available:
return available[locale_id]
# TODO: Look at other languages in the country?
# Give up and give nothing, or give first?
评论列表
文章目录