Allow the modules to define the i18n messages, and other messages

required by its javascript module.

This will allow us to load the javascript modules as a static file, and
not as a Jinja2 template. This will increase the load time, as it will
decrease number of templates to be processed during loading those
javascripts.
pull/3/head
Ashesh Vashi 2016-05-10 16:07:45 +05:30
parent d8cbee3850
commit 9cae686c65
3 changed files with 27 additions and 1 deletions

View File

@ -59,6 +59,13 @@ class PgAdmin(Flask):
stylesheets.extend(getattr(module, "stylesheets", []))
return stylesheets
@property
def messages(self):
messages = dict()
for module in self.submodules:
messages.update(getattr(module, "messages", dict()))
return messages
@property
def javascripts(self):
scripts = []

View File

@ -7,7 +7,7 @@ function(_, S, pgAdmin) {
if (pgBrowser.messages)
return pgBrowser.messages;
pgBrowser.messages = {
var messages = pgBrowser.messages = {
'SERVER_LOST': '{{ _('Connection to the server has been lost!') }}',
'CLICK_FOR_DETAILED_MSG': '%s<br><br>' + '{{ _('Click here for details.')|safe }}',
'GENERAL_CATEGORY': '{{ _("General")|safe }}',
@ -27,6 +27,9 @@ function(_, S, pgAdmin) {
'NOTE_CTRL_LABEL': "{{ _("Note") }}",
};
{% for key, val in current_app.messages.iteritems() %}messages['{{ key|safe }}'] = '{{ val|safe }}';
{% endfor %}
return pgBrowser.messages;
});

View File

@ -66,6 +66,14 @@ class PgAdminModule(Blueprint):
"""
return []
def get_own_messages(self):
"""
Returns:
dict: the i18n messages used by this module, not including any
messages needed by the submodules.
"""
return dict()
def get_own_javascripts(self):
"""
Returns:
@ -96,6 +104,14 @@ class PgAdminModule(Blueprint):
stylesheets.extend(module.stylesheets)
return stylesheets
@property
def messages(self):
res = self.get_own_messages()
for module in self.submodules:
res.update(module.messages)
return res
@property
def javascripts(self):
javascripts = self.get_own_javascripts()