Translations

pgAdmin supports multiple languages using the 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 (two letter) language codes. The codes are named $LANG in this document.

翻訳マーキング

文字列は、Pythonコード( gettext() を使用)またはJinjaテンプレート( gettext() を使用)のいずれかで翻訳用にマークできます。これがどのように達成されるかを示す例をいくつか示します。

Python:

errormsg = gettext('No server group name was specified')

ジンジャ:

<input type="submit" value="{{ _('Change Password') }}">
<title>{{ _('%(appname)s Password Change', appname=config.APP_NAME) }}</title>
define(['sources/gettext', ...], function(gettext, ...){
    ...
    var alert = alertify.prompt(
        gettext('Password Change'),
        gettext('New password for %(userName)s', {userName: 'jsmith' }),
        ...
    )
})

更新とマージ

アプリケーションに新しい文字列が追加されるたびに、テンプレートカタログ( web/pgadmin/messages.pot )と既存の翻訳カタログ( web/pgadmin/messages.pot )を更新してコンパイルする必要があります。これは、pgAdminのPython仮想環境の web/pgadmin/messages.pot ディレクトリから次のコマンドを使用して実現できます。

(pgadmin4) user$ pybabel extract -F babel.cfg -o pgadmin/messages.pot pgadmin

テンプレートを更新したら、既存のメッセージカタログにマージする必要があります。

(pgadmin4) user$ pybabel update -i pgadmin/messages.pot -d pgadmin/translations

最後に、メッセージカタログをコンパイルして使用できます。

(pgadmin4) user$ pybabel compile -d pgadmin/translations

新しい言語の追加

新しい言語を追加するのは簡単です。まず、言語名と識別子を web/config.py に追加します:

# Languages we support in the UI
LANGUAGES = {
    'en': 'English',
    'zh': 'Chinese (Simplified)',
    'de': 'German',
    'pl': 'Polish'
}

次に、pgAdminのPython仮想環境のソースツリーにある web ディレクトリから新しいメッセージカタログを作成します。

(pgadmin4) user$ pybabel init -i pgadmin/messages.pot -d pgadmin/translations -l $LANG