Revision c6e081ce
[#1721] Fusion traductions du thème et de l'appli
Change-Id: I1ac312bd3fc2deefd0a4ba9015189b3830d18748
Refs: #1721
vigiboard/controllers/root.py | ||
---|---|---|
261 | 261 |
localedir = os.path.join(conf['paths']['root'], 'i18n') |
262 | 262 |
|
263 | 263 |
lang = get_lang() |
264 |
modules = ( |
|
265 |
(conf['package'].__name__, localedir), |
|
266 |
('vigilo-themes', resource_filename('vigilo.themes.i18n', '')), |
|
267 |
) |
|
264 | 268 |
|
265 |
# Localise le fichier *.mo actuellement chargé |
|
266 |
# et génère le chemin jusqu'au *.js correspondant. |
|
267 |
filename = gettext.find(conf['package'].__name__, localedir, |
|
268 |
languages=lang) |
|
269 |
js = filename[:-3] + '.js' |
|
270 |
|
|
271 |
themes_filename = gettext.find( |
|
272 |
'vigilo-themes', |
|
273 |
resource_filename('vigilo.themes.i18n', ''), |
|
274 |
languages=lang) |
|
275 |
themes_js = themes_filename[:-3] + '.js' |
|
276 |
|
|
277 |
# Récupère et envoie le contenu du fichier de traduction *.js. |
|
278 |
fhandle = open(js, 'r') |
|
279 |
translations = fhandle.read() |
|
280 |
fhandle.close() |
|
281 |
|
|
282 |
fhandle = open(themes_js, 'r') |
|
283 |
translations += fhandle.read() |
|
284 |
fhandle.close() |
|
269 |
# Charge et installe le fichier JS de traduction de chaque module |
|
270 |
translations = "babel.Translations.load(" |
|
271 |
for domain, directory in modules: |
|
272 |
try: |
|
273 |
mofile = gettext.find(domain, directory, languages=lang) |
|
274 |
if mofile is None: |
|
275 |
continue |
|
276 |
|
|
277 |
fhandle = open(mofile[:-3] + '.js', 'r') |
|
278 |
translations += fhandle.read() |
|
279 |
fhandle.close() |
|
280 |
translations += ").load(" |
|
281 |
except ImportError: |
|
282 |
pass |
|
283 |
translations += "{}).install()" |
|
285 | 284 |
|
286 | 285 |
response.headers['Content-Type'] = 'text/javascript; charset=utf-8' |
287 | 286 |
return translations |
Also available in: Unified diff