Revision ef840436
[#1721] Fusion traductions du thème et de l'appli
Change-Id: I3c63552637ce9f5041fd19288d82c0ad52de1dec
Refs: #1721
vigigraph/controllers/root.py | ||
---|---|---|
67 | 67 |
localedir = os.path.join(conf['paths']['root'], 'i18n') |
68 | 68 |
|
69 | 69 |
lang = get_lang() |
70 |
modules = ( |
|
71 |
(conf['package'].__name__, localedir), |
|
72 |
('vigilo-themes', resource_filename('vigilo.themes.i18n', '')), |
|
73 |
('vigilo-vigigraph-enterprise', |
|
74 |
resource_filename('vigilo.vigigraph_enterprise.i18n', '')), |
|
75 |
) |
|
70 | 76 |
|
71 |
# Localise le fichier *.mo actuellement chargé |
|
72 |
# et génère le chemin jusqu'au *.js correspondant. |
|
73 |
filename = gettext.find(conf['package'].__name__, localedir, |
|
74 |
languages=lang) |
|
75 |
js = filename[:-3] + '.js' |
|
76 |
# Récupère et envoie le contenu du fichier de traduction *.js. |
|
77 |
fhandle = open(js, 'r') |
|
78 |
translations = fhandle.read() |
|
79 |
fhandle.close() |
|
80 |
|
|
81 |
# Même chose pour les thèmes |
|
82 |
themes_filename = gettext.find( |
|
83 |
'vigilo-themes', |
|
84 |
resource_filename('vigilo.themes.i18n', ''), |
|
85 |
languages=lang) |
|
86 |
themes_js = themes_filename[:-3] + '.js' |
|
87 |
fhandle = open(themes_js, 'r') |
|
88 |
translations += fhandle.read() |
|
89 |
fhandle.close() |
|
77 |
# Charge et installe le fichier JS de traduction de chaque module |
|
78 |
translations = "babel.Translations.load(" |
|
79 |
for domain, directory in modules: |
|
80 |
try: |
|
81 |
mofile = gettext.find(domain, directory, languages=lang) |
|
82 |
if mofile is None: |
|
83 |
continue |
|
90 | 84 |
|
91 |
# Extensions Enterprise |
|
92 |
try: |
|
93 |
ent_filename = gettext.find( |
|
94 |
'vigilo-vigigraph-enterprise', |
|
95 |
resource_filename('vigilo.vigigraph_enterprise.i18n', ''), |
|
96 |
languages=lang) |
|
97 |
except ImportError: |
|
98 |
pass |
|
99 |
else: |
|
100 |
# Le nom du fichier sera None s'il n'existe pas |
|
101 |
# de traductions dans la langue demandée. |
|
102 |
if ent_filename is not None: |
|
103 |
fhandle = open(ent_filename[:-3] + '.js', 'r') |
|
85 |
fhandle = open(mofile[:-3] + '.js', 'r') |
|
104 | 86 |
translations += fhandle.read() |
105 | 87 |
fhandle.close() |
88 |
translations += ").load(" |
|
89 |
except ImportError: |
|
90 |
pass |
|
91 |
translations += "{}).install()" |
|
106 | 92 |
|
107 | 93 |
response.headers['Content-Type'] = 'text/javascript; charset=utf-8' |
108 | 94 |
return translations |
Also available in: Unified diff