Project

General

Profile

Revision f6ecd27a

IDf6ecd27a7f88b318076de071178724bf9458cf24
Parent c6e081ce
Child b2668166

Added by Francois POIROTTE over 6 years ago

[#927] Fusion traductions des IHMs

Change-Id: I05fb4400ed6254b4b46b4356a89b197809724205
Refs: #927

View differences:

setup.py
90 90
            'groups = vigiboard.controllers.plugins.groups:PluginGroups',
91 91
            'masked_events = vigiboard.controllers.plugins.masked_events:PluginMaskedEvents',
92 92
            'map = vigiboard.controllers.plugins.map:PluginMap',
93
        ]
93
        ],
94
        'vigilo.turbogears.i18n': [
95
            'vigiboard = vigiboard.i18n:100',
96
        ],
94 97
    },
95 98
    cmdclass=cmdclass,
96 99
    data_files=[
vigiboard/controllers/root.py
39 39
from vigilo.turbogears.controllers.error import ErrorController
40 40
from vigilo.turbogears.controllers.autocomplete import AutoCompleteController
41 41
from vigilo.turbogears.controllers.proxy import ProxyController
42
from vigilo.turbogears.controllers.i18n import I18nController
42 43
from vigilo.turbogears.controllers.api.root import ApiRootController
43 44
from vigilo.turbogears.helpers import get_current_user
44 45

  
......
62 63
# W0613: Unused arguments: les arguments sont la query-string
63 64
# W0622: Redefining built-in 'id': élément de la query-string
64 65

  
65
class RootController(AuthController, SelfMonitoringController):
66
class RootController(AuthController, SelfMonitoringController, I18nController):
66 67
    """
67 68
    Le controller général de vigiboard
68 69
    """
......
251 252
        )
252 253

  
253 254

  
254
    @expose()
255
    def i18n(self):
256
        # Repris de tg.i18n:_get_translator.
257
        conf = config.current_conf()
258
        try:
259
            localedir = conf['localedir']
260
        except KeyError:
261
            localedir = os.path.join(conf['paths']['root'], 'i18n')
262

  
263
        lang = get_lang()
264
        modules = (
265
            (conf['package'].__name__, localedir),
266
            ('vigilo-themes', resource_filename('vigilo.themes.i18n', '')),
267
        )
268

  
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()"
284

  
285
        response.headers['Content-Type'] = 'text/javascript; charset=utf-8'
286
        return translations
287

  
288

  
289 255
    class MaskedEventsSchema(schema.Schema):
290 256
        """Schéma de validation de la méthode masked_events."""
291 257
        idcorrevent = validators.Int(not_empty=True)

Also available in: Unified diff