2015-11-02 12:23:46 +01:00
|
|
|
import re
|
2020-10-13 14:53:25 +02:00
|
|
|
import subprocess
|
2015-11-02 12:23:46 +01:00
|
|
|
from collections import defaultdict
|
|
|
|
|
2016-03-09 13:18:32 +01:00
|
|
|
from babel import Locale
|
|
|
|
|
2015-11-02 12:23:46 +01:00
|
|
|
authors_by_locale = defaultdict(set)
|
|
|
|
|
2022-02-14 14:25:00 +01:00
|
|
|
file_listing = subprocess.Popen(
|
2023-01-20 13:59:36 +01:00
|
|
|
"find ./wagtail -iname *.po", shell=True, stdout=subprocess.PIPE
|
2022-02-14 14:25:00 +01:00
|
|
|
)
|
2015-11-02 12:23:46 +01:00
|
|
|
|
|
|
|
for file_listing_line in file_listing.stdout:
|
|
|
|
filename = file_listing_line.strip()
|
|
|
|
|
|
|
|
# extract locale string from filename
|
2022-02-14 14:25:00 +01:00
|
|
|
locale = re.search(r"locale/(\w+)/LC_MESSAGES", str(filename)).group(1)
|
|
|
|
if locale == "en":
|
2015-11-02 12:23:46 +01:00
|
|
|
continue
|
|
|
|
|
|
|
|
# read author list from each file
|
2023-07-13 21:08:24 +02:00
|
|
|
with open(filename) as f:
|
2015-11-02 12:23:46 +01:00
|
|
|
has_found_translators_heading = False
|
|
|
|
for line in f:
|
|
|
|
line = line.strip()
|
2022-02-14 14:25:00 +01:00
|
|
|
if line.startswith("#"):
|
2015-11-02 12:23:46 +01:00
|
|
|
if has_found_translators_heading:
|
2022-02-14 14:25:00 +01:00
|
|
|
author_match = re.match(r"\# (.*), [\d\-]+", line)
|
2020-11-02 13:44:12 +01:00
|
|
|
if not author_match:
|
|
|
|
break
|
|
|
|
author = author_match.group(1)
|
2015-11-02 12:23:46 +01:00
|
|
|
authors_by_locale[locale].add(author)
|
2022-02-14 14:25:00 +01:00
|
|
|
elif line.startswith("# Translators:"):
|
2015-11-02 12:23:46 +01:00
|
|
|
has_found_translators_heading = True
|
|
|
|
else:
|
|
|
|
if has_found_translators_heading:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
raise Exception("No 'Translators:' heading found in %s" % filename)
|
|
|
|
|
2019-04-08 22:55:03 +02:00
|
|
|
|
|
|
|
LANGUAGE_OVERRIDES = {
|
2022-02-14 14:25:00 +01:00
|
|
|
"tet": "Tetum",
|
|
|
|
"ht": "Haitian",
|
2024-02-07 13:49:10 +01:00
|
|
|
"dv": "Divehi",
|
2019-04-08 22:55:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 = [
|
2019-04-08 22:55:03 +02:00
|
|
|
(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()
|
|
|
|
|
2023-11-17 00:43:25 +01:00
|
|
|
for language_name, locale in language_names:
|
2023-07-13 21:08:24 +02:00
|
|
|
print(f"{language_name} - {locale}") # noqa: T201
|
2023-06-12 19:40:09 +02:00
|
|
|
print("-----") # noqa: T201
|
2015-11-02 12:23:46 +01:00
|
|
|
for author in sorted(authors_by_locale[locale]):
|
2023-06-12 19:40:09 +02:00
|
|
|
print(author.replace("@", ".")) # noqa: T201
|
|
|
|
print("") # noqa: T201
|