diff --git a/horizon/contrib/bootstrap_datepicker.py b/horizon/contrib/bootstrap_datepicker.py index 3741fa689c..b4dc417932 100644 --- a/horizon/contrib/bootstrap_datepicker.py +++ b/horizon/contrib/bootstrap_datepicker.py @@ -63,6 +63,6 @@ LOCALE_MAPPING = { 'tr': 'tr', 'ua': 'ua', 'vi': 'vi', - 'zh-cn': 'zh-CN', - 'zh-tw': 'zh-TW', + 'zh-hans': 'zh-CN', + 'zh-hant': 'zh-TW', } diff --git a/horizon/management/commands/pull_catalog.py b/horizon/management/commands/pull_catalog.py index 8b3a24c8a7..3d89d8c7d7 100644 --- a/horizon/management/commands/pull_catalog.py +++ b/horizon/management/commands/pull_catalog.py @@ -28,15 +28,28 @@ POFILE = "{module}/locale/{locale}/LC_MESSAGES/{domain}.po" POFILE_URL = ("https://translate.openstack.org/rest/file/translation/{project}" "/{branch}/{language}/po?docId={module}%2Flocale%2F{domain}") +LOCALE_MAP = { + 'zh-CN': 'zh-Hans', + 'zh-TW': 'zh-Hant', +} +REV_LOCALE_MAP = dict((v, k) for k, v in LOCALE_MAP.items()) + class Command(BaseCommand): help = ("Pull a translation catalog from Zanata " "(https://translate.openstack.org) for all languages or a " "specified language") + def _to_horizon_lang_code(self, lang_code): + return LOCALE_MAP.get(lang_code, lang_code) + + def _to_zanata_lang_code(self, lang_code): + return REV_LOCALE_MAP.get(lang_code, lang_code) + def _get_language_codes(self): zanata_locales = requests.get(ZANATA_LOCALES_URL).json() - return [x['localeId'] for x in zanata_locales] + return [self._to_horizon_lang_code(x['localeId']) + for x in zanata_locales] def add_arguments(self, parser): language_codes = self._get_language_codes() @@ -78,7 +91,7 @@ class Command(BaseCommand): os.makedirs(pofile_dir) new_po = requests.get((POFILE_URL).format( - language=language, + language=self._to_zanata_lang_code(language), project=options['project'], branch=options['branch'], module=module, @@ -88,4 +101,4 @@ class Command(BaseCommand): new_po.encoding = 'utf-8' with open(pofile, 'w+') as f: - f.write(new_po.text.encode('utf-8')) + f.write(new_po.text) diff --git a/openstack_dashboard/management/commands/upgrade_check.py b/openstack_dashboard/management/commands/upgrade_check.py index c3c6697204..1f4e52cbcf 100644 --- a/openstack_dashboard/management/commands/upgrade_check.py +++ b/openstack_dashboard/management/commands/upgrade_check.py @@ -198,6 +198,22 @@ def check_required_settings(dummy=None): return upgradecheck.Result(upgradecheck.Code.SUCCESS) +@register_check(_("Chinese locale rename")) +def check_chinese_locale_rename(dummy): + # LANGUAGES setting is defined in Django, so we can assume + # it always exists. + langs = [code for code, name in settings.LANGUAGES] + if 'zh-cn' in langs or 'zh-tw' in langs: + return upgradecheck.Result( + upgradecheck.Code.FAILURE, + _("Chinese locale 'zh-cn' and 'zh-tw' must be renamed to " + "'zh-hans' and 'zh-hant' respectively in 'LANGUAGES' setting. " + "If you define them in local_settings.py or local_settings.d " + "explicitly, ensure to rename them to the new locales.") + ) + return upgradecheck.Result(upgradecheck.Code.SUCCESS) + + class UpgradeCheckTable(upgradecheck.UpgradeCommands): _upgrade_checks = CHECKS diff --git a/openstack_dashboard/settings.py b/openstack_dashboard/settings.py index 81b8e45e19..6253ef962c 100644 --- a/openstack_dashboard/settings.py +++ b/openstack_dashboard/settings.py @@ -199,8 +199,8 @@ LANGUAGES = ( ('pt-br', 'Portuguese (Brazil)'), ('ru', 'Russian'), ('tr', 'Turkish'), - ('zh-cn', 'Simplified Chinese'), - ('zh-tw', 'Chinese (Taiwan)'), + ('zh-hans', 'Simplified Chinese'), + ('zh-hant', 'Traditional Chinese'), ) LANGUAGE_CODE = 'en' LANGUAGE_COOKIE_NAME = 'horizon_language' diff --git a/releasenotes/notes/rename-chinese-locales-a6fb595bc373791f.yaml b/releasenotes/notes/rename-chinese-locales-a6fb595bc373791f.yaml new file mode 100644 index 0000000000..838787debb --- /dev/null +++ b/releasenotes/notes/rename-chinese-locales-a6fb595bc373791f.yaml @@ -0,0 +1,12 @@ +--- +features: + - | + Chinese locales ``zh-cn`` and ``zh-tw`` are now changed to ``zh-hans`` and + ``zh-hant`` respectively. This follows the change in Django which is a + framework horizon depends on. The new locales decouples what are spoken + from specific locations as they are also used outside of China/Taiwan. +upgrade: + - | + Chinese locales ``zh-cn`` and ``zh-tw`` have been changed to ``zh-hans`` + and ``zh-hant`` respectively. If you configure ``LANGUAGES`` in your + setting explicitly, ensure to use the new Chinese locales if needed.