mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2026-08-05 10:47:34 -05:00
Add a mechanism for centralising JS translations, to avoid having to render many JS files with Jinja.
This commit is contained in:
@@ -9,7 +9,11 @@
|
||||
|
||||
"""A blueprint module container for keeping all submodule of type tool."""
|
||||
|
||||
from flask import render_template, Response
|
||||
from flask import url_for
|
||||
from flask.ext.babel import get_translations
|
||||
from flask_babel import gettext
|
||||
|
||||
from pgadmin.utils import PgAdminModule
|
||||
from pgadmin.utils.ajax import bad_request
|
||||
|
||||
@@ -17,8 +21,11 @@ MODULE_NAME = 'tools'
|
||||
|
||||
class ToolsModule(PgAdminModule):
|
||||
def get_own_javascripts(self):
|
||||
from flask import url_for
|
||||
return [{
|
||||
'name': 'translations',
|
||||
'path': url_for('tools.index') + "translations",
|
||||
'when': None
|
||||
},{
|
||||
'name': 'pgadmin-sqlfoldcode',
|
||||
'path': url_for(
|
||||
'static',
|
||||
@@ -49,3 +56,13 @@ blueprint = ToolsModule(MODULE_NAME, __name__)
|
||||
def index():
|
||||
"""Calling tools index URL directly is not allowed."""
|
||||
return bad_request(gettext('This URL cannot be requested directly.'))
|
||||
|
||||
@blueprint.route("/translations.js")
|
||||
def translations():
|
||||
"""Return a js file that will handle translations so Flask interpolation can be isolated"""
|
||||
template = render_template("js/translations.js", translations=get_translations()._catalog)
|
||||
return Response(
|
||||
response=template,
|
||||
status=200,
|
||||
mimetype="application/javascript"
|
||||
)
|
||||
@@ -0,0 +1,4 @@
|
||||
define(function () {
|
||||
var translations = {{ translations|tojson }};
|
||||
return translations;
|
||||
});
|
||||
Reference in New Issue
Block a user