0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-24 19:17:48 +01:00
wagtail/scripts/get-translator-credits.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
1.9 KiB
Python
Raw Normal View History

import re
2020-10-13 14:53:25 +02:00
import subprocess
from collections import defaultdict
2016-03-09 13:18:32 +01:00
from babel import Locale
authors_by_locale = defaultdict(set)
file_listing = subprocess.Popen(
"find ./wagtail -iname *.po", shell=True, stdout=subprocess.PIPE
)
for file_listing_line in file_listing.stdout:
filename = file_listing_line.strip()
# extract locale string from filename
2017-03-07 12:50:14 +01:00
locale = re.search(r"locale/(\w+)/LC_MESSAGES", str(filename)).group(1)
if locale == "en":
continue
# read author list from each file
2023-07-13 21:08:24 +02:00
with open(filename) as f:
has_found_translators_heading = False
for line in f:
line = line.strip()
if line.startswith("#"):
if has_found_translators_heading:
2020-11-02 13:44:12 +01:00
author_match = re.match(r"\# (.*), [\d\-]+", line)
if not author_match:
break
author = author_match.group(1)
authors_by_locale[locale].add(author)
elif line.startswith("# Translators:"):
has_found_translators_heading = True
else:
if has_found_translators_heading:
break
else:
raise Exception("No 'Translators:' heading found in %s" % filename)
LANGUAGE_OVERRIDES = {
"tet": "Tetum",
2020-04-21 15:36:25 +02:00
"ht": "Haitian",
}
def get_language_name(locale_string):
try:
return LANGUAGE_OVERRIDES[locale_string]
except KeyError:
return Locale.parse(locale_string).english_name
2020-10-02 17:56:26 +02:00
2016-03-09 13:18:32 +01:00
language_names = [
(get_language_name(locale_string), locale_string)
2016-03-09 13:18:32 +01:00
for locale_string in authors_by_locale.keys()
]
language_names.sort()
for language_name, locale in language_names:
2023-07-13 21:08:24 +02:00
print(f"{language_name} - {locale}") # noqa: T201
print("-----") # noqa: T201
for author in sorted(authors_by_locale[locale]):
print(author.replace("@", ".")) # noqa: T201
print("") # noqa: T201