import jinja2
from mediagoblin.tools import staticdirect
-from mediagoblin.tools.translate import get_available_locales
+from mediagoblin.tools.translate import set_available_locales
from mediagoblin.init.config import (
read_mediagoblin_config, generate_validation_report)
from mediagoblin import mg_globals
def setup_locales():
"""Checks which language translations are available and sets them"""
- setup_globals(available_locales=get_available_locales())
+ set_available_locales()
def setup_global_and_app_config(config_path):
# A thread-local scope
thread_scope = threading.local()
-# a list of translated locales
-available_locales = None
# gettext (this will be populated on demand with gettext.Translations)
thread_scope.translations = None
# Translation tools
###################
-
+AVAILABLE_LOCALES = None
TRANSLATIONS_PATH = pkg_resources.resource_filename(
'mediagoblin', 'i18n')
-def get_available_locales():
- """Return a list of locales for which we have translations"""
- locales=[]
+def set_available_locales():
+ """Set available locales for which we have translations"""
+ global AVAILABLE_LOCALES
+ locales=['en', 'en_US'] # these are available without translations
for locale in localedata.list():
if gettext.find('mediagoblin', TRANSLATIONS_PATH, [locale]):
locales.append(locale)
- return locales
+ AVAILABLE_LOCALES = locales
def locale_to_lower_upper(locale):
Figure out what target language is most appropriate based on the
request
"""
+ global AVAILABLE_LOCALES
request_form = request.args or request.form
if request_form.has_key('lang'):
# TODO: We need a list of available locales, and match with the list
# of accepted locales, and serve the best available locale rather than
# the most preferred, or fall back to 'en' immediately.
- target_lang = request.accept_languages.best_match(
- mg_globals.available_locales) or 'en'
+ target_lang = request.accept_languages.best_match(AVAILABLE_LOCALES)
return locale_to_lower_upper(target_lang)