How do I enable translation to other languages in Openstack Horizon?

249 Views Asked by At

I am tasked to enable different languages in Openstack Horizon.

I am working on a horizon page built on top of dev stack. The Horizon page is pulled from here: https://github.com/openstack/horizon. I want to enable translation to different languages in Horizon.

I tried to follow this documentation: https://docs.openstack.org/horizon/latest/contributor/topics/translation.html

This is an example of my code, I am trying to translate this phrase: “API Access” found in the panel on the main page : Before editing the code, I saw that there is a corresponding translated message in openstack_dashboard/locale/zh_CN/LC_MESSAGES/django.po:

msgid "API Access"
msgstr "访问API"

This is what I did:

Firstly, In openstack_dashboard/dashboards/project/api_access/panel.py, I edited name = _("API Access") to name=pgettext("API Access", "API Access"):

from django.utils.translation import pgettext
import horizon

class ApiAccess(horizon.Panel):
     name = pgettext("API Access","API Access")
     slug = 'api_access'

Secondly, I ran tox -e manage -- extract_messages in the main openstack/horizon folder

Thirdly, I ran tox -e manage -- update_catalog in the main openstack/horizon folder

After I run it, this following keyword "API Access" is still not translated. (i.e. I started horizon, went to settings, and change the language to zh-cn. But the word "API Access" is still in English.)

Not sure if this is helpful: In openstack_dashboard/locale/Django.pot, I see this:

#: openstack_dashboard.dashboards/project/api_access/panel.py:22
msgctxt "API Access"
msgid "API Access"
msgstr ""

Grateful to anyone who can help me solve this translation issue.

1

There are 1 best solutions below

0
On

Nevermind, I manage to fix it by switching to clean branch and just follow the documentation!