Merge "Rename zh-cn and zh-tw translations to zh-hans and zh-hant"

This commit is contained in:
Zuul 2021-03-04 08:08:14 +00:00 committed by Gerrit Code Review
commit 394423147c
5 changed files with 48 additions and 7 deletions

View File

@ -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',
}

View File

@ -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)

View File

@ -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

View File

@ -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'

View File

@ -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.