From 2e9c2bb84da86f40c152aa15854593d383be9c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 18 Jul 2022 15:06:28 +0200 Subject: [PATCH] formats: Add appstore languge naming This is merely a BCP style with few overrides. Fixes #5522 --- docs/admin/languages.rst | 9 +++++++-- weblate/formats/base.py | 12 ++++++++++++ weblate/formats/txt.py | 2 +- weblate/trans/models/component.py | 1 + 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/admin/languages.rst b/docs/admin/languages.rst index 87b639363ad4..c1b5d5ea4fd4 100644 --- a/docs/admin/languages.rst +++ b/docs/admin/languages.rst @@ -200,11 +200,16 @@ BCP style using hyphen as a separator BCP style using hyphen as a separator, including country code BCP style language code including the country code even when not necessary (for example ``cs-CZ``). +BCP style using hyphen as a separator, legacy language codes + Uses legacy codes for Chinese and BCP style notation. +BCP style using hyphen as a separator, lower cased + BCP style notation, all in lower case (for examle ``cs-cz``). +App store metadata style + Style suitable for uploading metadata to appstores. This should be suitable + for both Apple App Store and Google Play Store. Android style Only used in Android apps, produces language codes like ``pt-rBR``. -BCP style using hyphen as a separator, legacy language codes - Uses legacy codes for Chinese and BCP style notation. Linux style Locales as used by Linux, uses legacy codes for Chinese and POSIX style notation. diff --git a/weblate/formats/base.py b/weblate/formats/base.py index 0f3bff773091..58ca497ba7c1 100644 --- a/weblate/formats/base.py +++ b/weblate/formats/base.py @@ -45,6 +45,13 @@ "zh_Hans_SG": "zh_SG", "zh_Hant_HK": "zh_HK", } +APPSTORE_CODES = { + "ar": "ar-SA", + "de": "de-DE", + "fr": "fr-FR", + "nl": "nl-NL", + "pt": "pt-PT", +} class UnitNotFound(Exception): @@ -490,6 +497,11 @@ def get_language_bcp_legacy(cls, code: str) -> str: """BCP, but doesn't use Hans/Hant, but rather TW/CN variants.""" return cls.get_language_bcp(cls.get_language_linux(code)) + @classmethod + def get_language_appstore(cls, code: str) -> str: + """App store language codes.""" + return cls.get_language_bcp(APPSTORE_CODES.get(code, code)) + @classmethod def get_language_filename(cls, mask: str, code: str) -> str: """ diff --git a/weblate/formats/txt.py b/weblate/formats/txt.py index 892422f26743..a12be8af1b66 100644 --- a/weblate/formats/txt.py +++ b/weblate/formats/txt.py @@ -191,7 +191,7 @@ class AppStoreFormat(TranslationFormat): monolingual = True unit_class = TextUnit simple_filename = False - language_format = "bcp_legacy" + language_format = "appstore" create_style = "directory" def load(self, storefile, template_store): diff --git a/weblate/trans/models/component.py b/weblate/trans/models/component.py index 0ea3091ee9fb..3f5cfa8b2a5d 100644 --- a/weblate/trans/models/component.py +++ b/weblate/trans/models/component.py @@ -141,6 +141,7 @@ "bcp_legacy", gettext_lazy("BCP style using hyphen as a separator, legacy language codes"), ), + ("appstore", gettext_lazy("App store metadata style")), ("linux", gettext_lazy("Linux style")), )