2018-06-15 03:14:12 -05:00
|
|
|
*********************
|
|
|
|
`Translations`:index:
|
|
|
|
*********************
|
2015-02-25 11:06:00 -06:00
|
|
|
|
2017-04-18 09:02:35 -05:00
|
|
|
pgAdmin supports multiple languages using the `Flask-Babel
|
|
|
|
<https://pythonhosted.org/Flask-Babel/>`_ Python module. A list of supported
|
|
|
|
languages is included in the **web/config.py** configuration file and must be
|
|
|
|
updated whenever languages are added or removed with
|
|
|
|
`ISO 639-1 <https://en.wikipedia.org/wiki/ISO_639-1>`_ (two letter) language
|
|
|
|
codes. The codes are named **$LANG** in this document.
|
2015-02-25 11:06:00 -06:00
|
|
|
|
|
|
|
Translation Marking
|
2019-03-08 09:29:05 -06:00
|
|
|
*******************
|
2015-02-25 11:06:00 -06:00
|
|
|
|
|
|
|
Strings can be marked for translation in either Python code (using **gettext()**)
|
2017-04-18 09:02:35 -05:00
|
|
|
or Jinja templates (using **_()**). Here are some examples that show how this
|
2015-02-25 11:06:00 -06:00
|
|
|
is achieved.
|
|
|
|
|
2019-03-08 09:29:05 -06:00
|
|
|
Python:
|
|
|
|
|
|
|
|
.. code-block:: python
|
2015-02-25 11:06:00 -06:00
|
|
|
|
|
|
|
errormsg = gettext('No server group name was specified')
|
2017-04-18 09:02:35 -05:00
|
|
|
|
2015-02-25 11:06:00 -06:00
|
|
|
Jinja:
|
|
|
|
|
|
|
|
.. code-block:: html
|
|
|
|
|
|
|
|
<input type="submit" value="{{ _('Change Password') }}">
|
2017-04-18 09:02:35 -05:00
|
|
|
|
2015-02-25 11:06:00 -06:00
|
|
|
.. code-block:: html
|
|
|
|
|
|
|
|
<title>{{ _('%(appname)s Password Change', appname=config.APP_NAME) }}</title>
|
2017-04-18 09:02:35 -05:00
|
|
|
|
2015-02-25 11:06:00 -06:00
|
|
|
.. code-block:: javascript
|
|
|
|
|
2017-03-28 14:21:49 -05:00
|
|
|
define(['sources/gettext', ...], function(gettext, ...){
|
2015-02-25 11:06:00 -06:00
|
|
|
...
|
2017-03-24 06:40:51 -05:00
|
|
|
var alert = alertify.prompt(
|
2017-03-28 14:21:49 -05:00
|
|
|
gettext('Password Change'),
|
|
|
|
gettext('New password for %(userName)s', {userName: 'jsmith' }),
|
2017-03-24 06:40:51 -05:00
|
|
|
...
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2017-04-18 09:02:35 -05:00
|
|
|
|
2015-02-25 11:06:00 -06:00
|
|
|
Updating and Merging
|
2019-03-08 09:29:05 -06:00
|
|
|
********************
|
2015-02-25 11:06:00 -06:00
|
|
|
|
2017-04-18 09:02:35 -05:00
|
|
|
Whenever new strings are added to the application, the template catalogue
|
|
|
|
(**web/pgadmin/messages.pot**) and the existing translation
|
2019-03-08 09:29:05 -06:00
|
|
|
catalogues (**web/pgadmin/translations/$LANG/LC_MESSAGES/messages.po**) must be
|
|
|
|
updated and compiled. This can be achieved using the following commands from the
|
2017-04-18 09:02:35 -05:00
|
|
|
**web** directory in the Python virtual environment for pgAdmin:
|
2015-02-25 11:06:00 -06:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2017-04-18 09:02:35 -05:00
|
|
|
(pgadmin4) user$ pybabel extract -F babel.cfg -o pgadmin/messages.pot pgadmin
|
2015-02-25 11:06:00 -06:00
|
|
|
|
2017-04-18 09:02:35 -05:00
|
|
|
Once the template has been updated it needs to be merged into the existing
|
|
|
|
message catalogues:
|
2015-02-25 11:06:00 -06:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2017-04-18 09:02:35 -05:00
|
|
|
(pgadmin4) user$ pybabel update -i pgadmin/messages.pot -d pgadmin/translations
|
2015-02-25 11:06:00 -06:00
|
|
|
|
|
|
|
Finally, the message catalogues can be compiled for use:
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2017-04-18 09:02:35 -05:00
|
|
|
(pgadmin4) user$ pybabel compile -d pgadmin/translations
|
2015-02-25 11:06:00 -06:00
|
|
|
|
2017-04-18 09:02:35 -05:00
|
|
|
Adding a New Language
|
2019-03-08 09:29:05 -06:00
|
|
|
*********************
|
2015-02-25 11:06:00 -06:00
|
|
|
|
|
|
|
Adding a new language is simple. First, add the language name and identifier to
|
|
|
|
**web/config.py**::
|
|
|
|
|
|
|
|
# Languages we support in the UI
|
|
|
|
LANGUAGES = {
|
|
|
|
'en': 'English',
|
2017-04-18 09:02:35 -05:00
|
|
|
'zh': 'Chinese (Simplified)',
|
|
|
|
'de': 'German',
|
|
|
|
'pl': 'Polish'
|
2015-02-25 11:06:00 -06:00
|
|
|
}
|
|
|
|
|
2017-04-18 09:02:35 -05:00
|
|
|
Then, create the new message catalogue from the **web** directory in the source
|
|
|
|
tree in the Python virtual environment for pgAdmin:
|
2015-02-25 11:06:00 -06:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2017-04-18 09:02:35 -05:00
|
|
|
(pgadmin4) user$ pybabel init -i pgadmin/messages.pot -d pgadmin/translations -l $LANG
|