Skip to content

Commit

Permalink
formats: Add appstore languge naming
Browse files Browse the repository at this point in the history
This is merely a BCP style with few overrides.

Fixes #5522
  • Loading branch information
nijel committed Jul 19, 2022
1 parent c4f23ef commit 2e9c2bb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
9 changes: 7 additions & 2 deletions docs/admin/languages.rst
Expand Up @@ -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.

Expand Down
12 changes: 12 additions & 0 deletions weblate/formats/base.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
"""
Expand Down
2 changes: 1 addition & 1 deletion weblate/formats/txt.py
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions weblate/trans/models/component.py
Expand Up @@ -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")),
)

Expand Down

0 comments on commit 2e9c2bb

Please sign in to comment.