зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1805297 - Update name and description for language packs to fit within manifest.json limits, r=eemeli
manifest.json has character limits for name (45) and description (132). Language packs now use: name: Language: {native_name} ({english_name}) description: {app} Language Pack for {native_name} ({locale_code}) – {english_name} The English name is omitted if identical to the native name, and it's omitted from the name if the resulting name exceeds the character limit. Longer name or description are always truncated. Differential Revision: https://phabricator.services.mozilla.com/D164535
This commit is contained in:
Родитель
f904631557
Коммит
ac2d5ca725
|
@ -166,7 +166,11 @@ def parse_flat_ftl(path):
|
|||
# Record<string, { native: string, english?: string }>
|
||||
#
|
||||
# If an English name is given and is different from the native one,
|
||||
# it will be included parenthetically in the title.
|
||||
# it will be included in the description and, if within the character limits,
|
||||
# also in the name.
|
||||
#
|
||||
# Length limit for names is 45 characters, for descriptions is 132,
|
||||
# return values are truncated if needed.
|
||||
#
|
||||
# NOTE: If you're updating the native locale names,
|
||||
# you should also update the data in
|
||||
|
@ -184,19 +188,30 @@ def get_title_and_description(app, locale):
|
|||
dir = os.path.dirname(__file__)
|
||||
with open(os.path.join(dir, "langpack_localeNames.json"), encoding="utf-8") as nf:
|
||||
names = json.load(nf)
|
||||
|
||||
nameCharLimit = 45
|
||||
descCharLimit = 132
|
||||
nameTemplate = "Language: {}"
|
||||
descTemplate = "{} Language Pack for {}"
|
||||
|
||||
if locale in names:
|
||||
data = names[locale]
|
||||
native = data["native"]
|
||||
english = data["english"] if "english" in data else native
|
||||
titleName = f"{native} ({english})" if english != native else native
|
||||
descName = f"{native} ({locale})"
|
||||
else:
|
||||
titleName = locale
|
||||
descName = locale
|
||||
|
||||
title = f"Language Pack: {titleName}"
|
||||
description = f"{app} Language Pack for {descName}"
|
||||
return title, description
|
||||
if english != native:
|
||||
title = nameTemplate.format(f"{native} ({english})")
|
||||
if len(title) > nameCharLimit:
|
||||
title = nameTemplate.format(native)
|
||||
description = descTemplate.format(app, f"{native} ({locale}) – {english}")
|
||||
else:
|
||||
title = nameTemplate.format(native)
|
||||
description = descTemplate.format(app, f"{native} ({locale})")
|
||||
else:
|
||||
title = nameTemplate.format(locale)
|
||||
description = descTemplate.format(app, locale)
|
||||
|
||||
return title[:nameCharLimit], description[:descCharLimit]
|
||||
|
||||
|
||||
###
|
||||
|
|
|
@ -57,12 +57,65 @@ langpack-contributors = { "" }
|
|||
)
|
||||
|
||||
data = json.loads(manifest)
|
||||
self.assertEqual(data["name"], "Language Pack: Suomi (Finnish)")
|
||||
self.assertEqual(data["name"], "Language: Suomi (Finnish)")
|
||||
self.assertEqual(
|
||||
data["description"], "Firefox Language Pack for Suomi (fi) – Finnish"
|
||||
)
|
||||
self.assertEqual(
|
||||
data["author"], "Suomennosprojekti (contributors: Joe Smith, Mary White)"
|
||||
)
|
||||
self.assertEqual(data["version"], "57.0.1buildid20210928.100000")
|
||||
|
||||
def test_manifest_truncated_name(self):
|
||||
ctx = {
|
||||
"langpack-creator": "Mozilla.org / Softcatalà",
|
||||
"langpack-contributors": "Joe Smith, Mary White",
|
||||
}
|
||||
os.environ["MOZ_BUILD_DATE"] = "20210928100000"
|
||||
manifest = langpack_manifest.create_webmanifest(
|
||||
"ca-valencia",
|
||||
"57.0.1",
|
||||
"57.0",
|
||||
"57.0.*",
|
||||
"Firefox",
|
||||
"/var/vcs/l10n-central",
|
||||
"langpack-ca-valencia@firefox.mozilla.og",
|
||||
ctx,
|
||||
{},
|
||||
)
|
||||
|
||||
data = json.loads(manifest)
|
||||
self.assertEqual(data["name"], "Language: Català (Valencià)")
|
||||
self.assertEqual(
|
||||
data["description"],
|
||||
"Firefox Language Pack for Català (Valencià) (ca-valencia) – Catalan, Valencian",
|
||||
)
|
||||
|
||||
def test_manifest_name_untranslated(self):
|
||||
ctx = {
|
||||
"langpack-creator": "Mozilla.org",
|
||||
"langpack-contributors": "Joe Smith, Mary White",
|
||||
}
|
||||
os.environ["MOZ_BUILD_DATE"] = "20210928100000"
|
||||
manifest = langpack_manifest.create_webmanifest(
|
||||
"en-US",
|
||||
"57.0.1",
|
||||
"57.0",
|
||||
"57.0.*",
|
||||
"Firefox",
|
||||
"/var/vcs/l10n-central",
|
||||
"langpack-ca-valencia@firefox.mozilla.og",
|
||||
ctx,
|
||||
{},
|
||||
)
|
||||
|
||||
data = json.loads(manifest)
|
||||
self.assertEqual(data["name"], "Language: English (US)")
|
||||
self.assertEqual(
|
||||
data["description"],
|
||||
"Firefox Language Pack for English (US) (en-US)",
|
||||
)
|
||||
|
||||
def test_manifest_without_contributors(self):
|
||||
ctx = {
|
||||
"langpack-creator": "Suomennosprojekti",
|
||||
|
@ -81,9 +134,25 @@ langpack-contributors = { "" }
|
|||
)
|
||||
|
||||
data = json.loads(manifest)
|
||||
self.assertEqual(data["name"], "Language Pack: Suomi (Finnish)")
|
||||
self.assertEqual(data["name"], "Language: Suomi (Finnish)")
|
||||
self.assertEqual(
|
||||
data["description"], "Firefox Language Pack for Suomi (fi) – Finnish"
|
||||
)
|
||||
self.assertEqual(data["author"], "Suomennosprojekti")
|
||||
|
||||
def test_manifest_truncation(self):
|
||||
locale = (
|
||||
"Long locale code that will be truncated and will cause both "
|
||||
"the name and the description to exceed the maximum number of "
|
||||
"characters allowed in manifest.json"
|
||||
)
|
||||
title, description = langpack_manifest.get_title_and_description(
|
||||
"Firefox", locale
|
||||
)
|
||||
|
||||
self.assertEqual(len(title), 45)
|
||||
self.assertEqual(len(description), 132)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
mozunit.main()
|
||||
|
|
Загрузка…
Ссылка в новой задаче