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() を使用して翻訳用にマークできます。次に、これを実現する方法を示す例をいくつか示します。
パイソン
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