From 9af1c5660b01a24e140067aff399050844b500f9 Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Tue, 16 Feb 2016 02:59:43 +0900 Subject: [PATCH] Translation setup for sahara-dashboard In Liberty, sahara-dashboard supports translations, but does not now. Once this patch is merged, we can enable the infra tranlation jobs. * Prepare babel-{django|djangojs}.cfg so that the infra script extracts message catalogs [1] * Update devstack plugin to compile message catalogs * Remove babel related entries in setup.cfg because it does not work for horizon plugins. Babel does not support message extraction for multiple domains. * Create symlink sahara_dashboard/content/data_processing/locale (which points to sahara_dashboard/locale) The infra translation script assumes /locale as locale dir. On the other hand, sahara dashboard registers "sahara_dashboard.content.data_processing" in INSTALLED_APPS. Django search locale data from /locale for each INSTALLED_APPS. Thus this symlink is required to make translation work. Note that I am not sure why sahara dashboard uses "sahara_dashboard.content.data_processing" as INSTALLED_APPS unlike other horizon related projects, but it needs more investigation and this patch does not touch it at the moment. [1] http://docs.openstack.org/infra/manual/creators.html#enabling-translation-infrastructure Change-Id: I93609a1af08b5a6f64fc43c16722f4c759f68302 --- babel-django.cfg | 5 +++++ babel-djangojs.cfg | 14 ++++++++++++++ devstack/plugin.sh | 10 ++++++++++ sahara_dashboard/content/data_processing/locale | 1 + setup.cfg | 14 -------------- 5 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 babel-django.cfg create mode 100644 babel-djangojs.cfg create mode 120000 sahara_dashboard/content/data_processing/locale diff --git a/babel-django.cfg b/babel-django.cfg new file mode 100644 index 00000000..e78d6c0f --- /dev/null +++ b/babel-django.cfg @@ -0,0 +1,5 @@ +[extractors] +django = django_babel.extract:extract_django + +[python: **.py] +[django: **/templates/**.html] diff --git a/babel-djangojs.cfg b/babel-djangojs.cfg new file mode 100644 index 00000000..a8273b62 --- /dev/null +++ b/babel-djangojs.cfg @@ -0,0 +1,14 @@ +[extractors] +# We use a custom extractor to find translatable strings in AngularJS +# templates. The extractor is included in horizon.utils for now. +# See http://babel.pocoo.org/docs/messages/#referencing-extraction-methods for +# details on how this works. +angular = horizon.utils.babel_extract_angular:extract_angular + +[javascript: **.js] + +# We need to look into all static folders for HTML files. +# The **/static ensures that we also search within +# /openstack_dashboard/dashboards/XYZ/static which will ensure +# that plugins are also translated. +[angular: **/static/**.html] diff --git a/devstack/plugin.sh b/devstack/plugin.sh index a9eadef2..f8f99482 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -8,6 +8,16 @@ function install_sahara_dashboard { function configure_sahara_dashboard { cp -a ${SAHARA_DASH_DIR}/sahara_dashboard/enabled/* ${DEST}/horizon/openstack_dashboard/local/enabled/ + # compile message catalogs + # NOTE: "python manage.py compilemessages does not work" + # so we compile translation catalogs directly. + if [ -d sahara_dashboard/locale ]; then + for domain in django djangojs; do + if find sahara_dashboard/locale -type f | grep -q "${domain}.po$"; then + pybabel compile -D ${domain} -d sahara_dashboard/locale + fi + done + fi } # check for service enabled diff --git a/sahara_dashboard/content/data_processing/locale b/sahara_dashboard/content/data_processing/locale new file mode 120000 index 00000000..853389b9 --- /dev/null +++ b/sahara_dashboard/content/data_processing/locale @@ -0,0 +1 @@ +../../locale \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 92ee06b5..5bfd8918 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,17 +30,3 @@ all_files = 1 [upload_sphinx] upload-dir = doc/build/html - -[compile_catalog] -directory = sahara_dashboard/locale -domain = sahara-dashboard - -[update_catalog] -domain = sahara-dashboard -output_dir = sahara_dashboard/locale -input_file = sahara_dashboard/locale/sahara_dashboard.pot - -[extract_messages] -keywords = _ gettext ngettext l_ lazy_gettext -mapping_file = babel.cfg -output_file = sahara_dashboard/locale/sahara_dashboard.pot