ZUN UI国際化
運用の実装
コントロールノード
sudo -i
# horizon
lxc-attach -n infra1_horizon_container-314417a3
# zunui-i18n
mkdir ~/zunui-i18n
#
cd ~/zunui-i18n
#
rz
#
cp /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/django.po /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/django.po.bak
cp /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/djangojs.po /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/djangojs.po.bak
cp /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/dashboard/container/containers/details/console.controller.js /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/dashboard/container/containers/details/console.controller.js.bak
cp /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/cloud-shell/cloud-shell.controller.js /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/cloud-shell/cloud-shell.controller.js.bak
#
cp ~/zunui-i18n/django.po /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/
chown root:root /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/django.po
chmod 644 /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/django.po
cp ~/zunui-i18n/djangojs.po /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/
chown root:root /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/djangojs.po
chmod 644 /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/djangojs.po
cp ~/zunui-i18n/console.controller.js /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/dashboard/container/containers/details/
chown root:root /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/dashboard/container/containers/details/console.controller.js
chmod 644 /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/dashboard/container/containers/details/console.controller.js
cp ~/zunui-i18n/cloud-shell.controller.js /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/cloud-shell/
chown root:root /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/cloud-shell/cloud-shell.controller.js
chmod 644 /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/cloud-shell/cloud-shell.controller.js
# po
msgfmt --statistics --verbose -o /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/django.mo /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/django.po
msgfmt --statistics --verbose -o /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/djangojs.mo /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/djangojs.po
#
/openstack/venvs/horizon-18.1.5/bin/horizon-manage.py collectstatic --noinput
/openstack/venvs/horizon-18.1.5/bin/horizon-manage.py compress --force
# Apache
systemctl restart apache2
systemctl status apache2
( i18n-zunui.sh 。)
説明
次のようなファイルを置換します.#
i18n-zunui.sh
# js
djangojs.po
# py
django.po
# ,console controller
console.controller.js
# cloud-shell controller , , 。。。
cloud-shell.controller.js
上書きされたファイルはどのような内容を変更しましたか?
sudo -i
# horizon
lxc-attach -n infra1_horizon_container-314417a3
# zunui-i18n
mkdir ~/zunui-i18n
#
cd ~/zunui-i18n
#
rz
#
cp /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/django.po /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/django.po.bak
cp /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/djangojs.po /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/djangojs.po.bak
cp /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/dashboard/container/containers/details/console.controller.js /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/dashboard/container/containers/details/console.controller.js.bak
cp /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/cloud-shell/cloud-shell.controller.js /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/cloud-shell/cloud-shell.controller.js.bak
#
cp ~/zunui-i18n/django.po /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/
chown root:root /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/django.po
chmod 644 /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/django.po
cp ~/zunui-i18n/djangojs.po /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/
chown root:root /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/djangojs.po
chmod 644 /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/djangojs.po
cp ~/zunui-i18n/console.controller.js /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/dashboard/container/containers/details/
chown root:root /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/dashboard/container/containers/details/console.controller.js
chmod 644 /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/dashboard/container/containers/details/console.controller.js
cp ~/zunui-i18n/cloud-shell.controller.js /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/cloud-shell/
chown root:root /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/cloud-shell/cloud-shell.controller.js
chmod 644 /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/static/cloud-shell/cloud-shell.controller.js
# po
msgfmt --statistics --verbose -o /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/django.mo /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/django.po
msgfmt --statistics --verbose -o /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/djangojs.mo /openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/djangojs.po
#
/openstack/venvs/horizon-18.1.5/bin/horizon-manage.py collectstatic --noinput
/openstack/venvs/horizon-18.1.5/bin/horizon-manage.py compress --force
# Apache
systemctl restart apache2
systemctl status apache2
( i18n-zunui.sh 。)
次のようなファイルを置換します.
#
i18n-zunui.sh
# js
djangojs.po
# py
django.po
# ,console controller
console.controller.js
# cloud-shell controller , , 。。。
cloud-shell.controller.js
上書きされたファイルはどのような内容を変更しましたか?
function onGetContainer(container) {
//rwz add
var enableInteractiveModeTipStr = gettext("To display console," +
"interactive mode needs to be enabled when this container was created.");
var notRunningStr = gettext("Container is not running.");
ctrl.container = container.data;
var consoleUrl = webRoot + "containers/" + ctrl.container.id + "/console";
//var console = $("To display console, interactive mode needs to be enabled " +
// "when this container was created.");
var console = $(""
+ enableInteractiveModeTipStr + "");
if (ctrl.container.status !== "Running") {
//console = $("Container is not running.
");
console = $(""
+ notRunningStr +"");
} else if (ctrl.container.interactive) {
console = $("");
}
$("#console").append(console);
}
function onGetContainer(response) {
ctrl.container = response.data;
//rwz add
var enableInteractiveModeTipStr = gettext("To display console," +
"interactive mode needs to be enabled when this container was created.");
var notRunningStr = gettext("Container is not running.Please wait for starting up container.");
// attach console to existing container
ctrl.consoleUrl = webRoot + "containers/" + ctrl.container.id + "/console";
//var console = $("To display console, interactive mode needs to be enabled " +
// "when this container was created.");
var console = $(""
+ enableInteractiveModeTipStr + "");
if (ctrl.container.status !== "Running") {
//console = $("Container is not running. Please wait for starting up container.
");
console = $(""
+ notRunningStr + "");
} else if (ctrl.container.interactive) {
console = $("");
// execute openrc.sh on the container
var command = "sh -c 'printf \"" + cloudsYaml + "\" > ~/.config/openstack/clouds.yaml'";
zun.executeContainer(ctrl.container.id, {command: command}).then(function() {
var command = "sh -c 'printf \"export OS_CLOUD=openstack\" > ~/.bashrc'";
zun.executeContainer(ctrl.container.id, {command: command}).then(function() {
angular.noop();
});
});
}
// append shell content
angular.element("#shell-content").append(console);
}
ファイルの保存パス
Poファイルの場所:
/openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/openstack_dashboard/locale/zh_CN/LC_MESSAGES/
zun-uiディレクトリの場所:
/openstack/venvs/horizon-18.1.5/lib/python2.7/site-packages/zun_ui/
国際化の主な考え方
ソースファイルの国際化に関する部分を検索します:py、jsファイルの中でgettext()メソッドを呼び出して、htmlはtranslateタグの部分を使って、出現位置のコンテキストと結びつけて翻訳します.ここで、jsファイルとhtmlファイルの翻訳はdjangojsに置く.Poファイルではpyファイルの翻訳をdjangoに置く.Poファイルにあります.国際化手法を用いずに、直接ページに英語を表示する場合は、必要に応じてコードを修正して国際化をサポートするかどうかを決定します.
いくつかの問題に直面した。
一語多義
msgctxtタグを使用して、コンテキスト情報を追加します.したがって、gettextメソッドをngettextメソッドに変更します.(未検証)
po :
msgctxt "month name"
msgid "May"
msgstr ""
template :
{% trans "May" context "month name" %}
参考:python国際化という言葉の多義翻訳
ソースコードに国際化は考慮されていません
ページに直接出力する場合は、zun_ui/static/dashboard/container/containers/details/console.controller.js zun_ui/static/cloud-shell/cloud-shell.controller.jsはコードを適切に修正し、gettextメソッドを呼び出し、国際化を実現する必要がある.
apiから取得したデータについては、zun_ui/static/dashboard/container/containers/containers.module.jsはfilterを増やして国際化された情報を処理する必要がある.
//angular.module****
.filter('translatetext', getTranslateText)
//containerProperties() , , status, filter
'status': {label: gettext('Status'), filters: ['noValue', 'translatetext'] },
function getTranslateText() {
return function(input){
return gettext(input);
}
}
ここで、必要に応じて、適切な国際化/フィルタリング操作を追加することができる.
htmlの複数行の内容
次のようになります.
<p translate>
When the <b>Admin Stateb> for a network is set to <b>Upb>,
then the network is available for use. You can set the <b>Admin Stateb> to <b>Downb>
if you are not ready for other users to access the network.
p>
翻訳するときは、msgidの内容はhtmlのフォーマットを保持し、スペース、改行を含め、先頭と末尾を問わず使用できます.
msgid ""
"When the Admin State for a network is set to Up,
"
" then the network is available for use. You can set the Admin State"
"b> to Down
"
" if you are not ready for other users to access the network."
msgstr ""
" ,
"
" 。 ,
"
" 。"