forked from IdentityPython/pyFF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi18n.py
30 lines (23 loc) · 866 Bytes
/
i18n.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
__author__ = 'leifj'
# -*- coding: utf-8 -*-
import gettext
import cherrypy
import locale
import os
# Change this variable to your app name!
# The translation files will be under
# @LOCALE_DIR@/@LANGUAGE@/LC_MESSAGES/@APP_NAME@.mo
APP_NAME = "pyFF"
# This is ok for maemo. Not sure in a regular desktop:
LOCALE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "i18n")
languages = [x.value.replace('-', '_') for x in cherrypy.request.headers.elements('Accept-Language')]
languages += ['en_US']
lc, encoding = locale.getdefaultlocale()
if lc:
languages += [lc]
mo_location = LOCALE_DIR
gettext.install(True, localedir=None, unicode=1)
gettext.find(APP_NAME, mo_location)
gettext.textdomain(APP_NAME)
gettext.bind_textdomain_codeset(APP_NAME, "UTF-8")
language = gettext.translation(APP_NAME, mo_location, languages=languages, fallback=True)