def get_default_locale_callable():
"""
Wrapper function so that the default mapping is only built when needed
"""
exec_dir = os.path.dirname(os.path.realpath(__file__))
xml_path = os.path.join(exec_dir, 'data', 'FacebookLocales.xml')
fb_locales = _build_locale_table(xml_path)
def default_locale(request):
"""
Guess an appropiate FB locale based on the active Django locale.
If the active locale is available, it is returned. Otherwise,
it tries to return another locale with the same language. If there
isn't one avaible, 'en_US' is returned.
"""
chosen = 'en_US'
language = get_language()
if language:
locale = to_locale(language)
lang, _, reg = locale.partition('_')
lang_map = fb_locales.get(lang)
if lang_map is not None:
if reg in lang_map['regs']:
chosen = lang + '_' + reg
else:
chosen = lang + '_' + lang_map['default']
return chosen
return default_locale
评论列表
文章目录