import yaml
import pytz
+from webob.acceptparse import create_accept_language_header
+
# Own modules
from fb_tools.common import pp, to_bytes, to_bool
from fb_tools.colored import ColoredFormatter
from .xlate import __module_dir__ as __xlate_module_dir__
from .xlate import __base_dir__ as __xlate_base_dir__
from .xlate import __mo_file__ as __xlate_mo_file__
-from .xlate import XLATOR, LOCALE_DIR, DOMAIN
+from .xlate import XLATOR, LOCALE_DIR, DOMAIN, SUPPORTED_LANGS
__version__ = __pkg_version__
re_selbstlaut = re.compile(r'^[ieaouy]', re.IGNORECASE)
+ default_charset = 'utf-8'
+ default_language = 'en_US'
+
open_args = {}
if six.PY3:
open_args = {
- 'encoding': 'utf-8',
+ 'encoding': default_charset,
'errors': 'surrogateescape',
}
self.search_curl_bin()
+ self.init_locales()
+
self.handler = BaseHandler(
appname=self.appname, verbose=self.verbose, base_dir=self.base_dir,
quiet=self.quiet, simulate=self.simulate)
return
+ # -------------------------------------------------------------------------
+ def init_locales(self):
+
+ accept_langs = os.getenv('HTTP_ACCEPT_LANGUAGE', None)
+ accept = create_accept_language_header(accept_langs)
+ lang = self.default_language + '.' + self.default_charset
+
+ if accept:
+ match = accept.best_match(SUPPORTED_LANGS)
+ if match:
+ lang = match + '.' + self.default_charset
+ LOG.debug("Setting 'LC_ALL' to {!r}.".format(lang))
+ os.putenv('LC_ALL', lang)
+
# -------------------------------------------------------------------------
def init_arg_parser(self):
"""
res['mail_subject'] = self.mail_subject
res['mail_headline'] = self.mail_headline
res['sort_by_name'] = self.sort_by_name
+ res['default_charset'] = self.default_charset
+ res['default_language'] = self.default_language
if 'xlate' not in res:
res['xlate'] = {}
'__base_dir__': __xlate_base_dir__,
'LOCALE_DIR': LOCALE_DIR,
'DOMAIN': DOMAIN,
+ 'SUPPORTED_LANGS': SUPPORTED_LANGS,
'__mo_file__': __xlate_mo_file__,
}