Project

General

Profile

Revision db6fbc92

IDdb6fbc9211c526c9ef3131ff61d490e02a50ffc7
Parent 70938860
Child aa6e5fe9

Added by Aurelien BOMPARD about 13 years ago

vigiboard: implémentation des traductions BabelJS

git-svn-id: https://vigilo-dev.si.c-s.fr/svn@6831 b22e2e97-25c9-44ff-b637-2e5ceca36478

View differences:

vigiboard/controllers/root.py
23 23
from datetime import datetime
24 24
from time import mktime
25 25

  
26
from pkg_resources import resource_filename
27

  
26 28
from tg.exceptions import HTTPNotFound
27 29
from tg import expose, validate, require, flash, url, \
28 30
    tmpl_context, request, config, session, redirect
29 31
from webhelpers import paginate
30 32
from tw.forms import validators
31
from pylons.i18n import ugettext as _, lazy_ugettext as l_
33
from pylons.i18n import ugettext as _, lazy_ugettext as l_, get_lang
32 34
from sqlalchemy import asc
33 35
from sqlalchemy.sql import func
34 36
from sqlalchemy.orm import aliased
......
208 210
        )
209 211

  
210 212

  
213
    @expose()
214
    def i18n(self):
215
        import gettext
216
        import pylons
217
        import os.path
218

  
219
        # Repris de pylons.i18n.translation:_get_translator.
220
        conf = pylons.config.current_conf()
221
        try:
222
            rootdir = conf['pylons.paths']['root']
223
        except KeyError:
224
            rootdir = conf['pylons.paths'].get('root_path')
225
        localedir = os.path.join(rootdir, 'i18n')
226

  
227
        lang = get_lang()
228

  
229
        # Localise le fichier *.mo actuellement chargé
230
        # et génère le chemin jusqu'au *.js correspondant.
231
        filename = gettext.find(conf['pylons.package'], localedir,
232
            languages=lang)
233
        js = filename[:-3] + '.js'
234

  
235
        themes_filename = gettext.find(
236
            'vigilo-themes',
237
            resource_filename('vigilo.themes.i18n', ''),
238
            languages=lang)
239
        themes_js = themes_filename[:-3] + '.js'
240

  
241
        # Récupère et envoie le contenu du fichier de traduction *.js.
242
        fhandle = open(js, 'r')
243
        translations = fhandle.read()
244
        fhandle.close()
245

  
246
        fhandle = open(themes_js, 'r')
247
        translations += fhandle.read()
248
        fhandle.close()
249
        return translations
250

  
251

  
211 252
    class MaskedEventsSchema(schema.Schema):
212 253
        """Schéma de validation de la méthode masked_events."""
213 254
        idcorrevent = validators.Int(not_empty=True)

Also available in: Unified diff