3 # Copyright (C) 2022 Wildfire Games.
4 # This file is part of 0 A.D.
6 # 0 A.D. is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 2 of the License, or
9 # (at your option) any later version.
11 # 0 A.D. is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
20 This file updates the translators credits located in the public mod GUI files, using
21 translators names from the .po files.
23 If translators change their names on Transifex, the script will remove the old names.
24 TODO: It should be possible to add people in the list manually, and protect them against
25 automatic deletion. This has not been needed so far. A possibility would be to add an
26 optional boolean entry to the dictionary containing the name.
28 Translatable strings will be extracted from the generated file, so this should be run
29 once before updateTemplates.py.
32 import json
, os
, glob
, re
34 from i18n_helper
import l10nFolderName
, transifexClientFolder
, projectRootDirectory
36 # We credit everyone that helps translating even if the translations don't
37 # make it into the game.
38 # Note: Needs to be edited manually when new languages are added on Transifex.
41 'ar': 'الدارجة (Arabic)',
43 'az': 'Azərbaycan dili',
45 'be': 'Беларуская мова (Belarusian)',
46 'bg': 'Български (Bulgarian)',
47 'bn': 'বাংলা (Bengali)',
54 'el': 'Ελληνικά (Greek)',
55 'en_GB': 'English (United Kingdom)',
58 'es_AR': 'Español (Argentina)',
59 'es_CL': 'Español (Chile)',
60 'es_MX': 'Español (Mexico)',
63 'fa': 'فارسی (Farsi)',
66 'fr_CA': 'Français (Canada)',
67 'frp': 'Franco-Provençal (Arpitan)',
71 'he': 'עברית (Hebrew)',
72 'hi': 'हिन्दी (Hindi)',
75 'hy': 'Հայերէն (Armenian)',
76 'id': 'Bahasa Indonesia',
78 'ja': '日本語 (Japanese)',
80 'ka': 'ქართული ენა (Georgian)',
82 'krl': 'Karjalan kieli',
83 'ku': 'کوردی (Kurdish)',
85 'lt': 'Lietuvių kalba',
86 'lv': 'Latviešu valoda',
87 'mk': 'македонски (Macedonian)',
88 'ml': 'മലയാളം (Malayalam)',
89 'mr': 'मराठी (Marathi)',
90 'ms': 'بهاس ملايو (Malay)',
94 'pt_BR': 'Português (Brazil)',
95 'pt_PT': 'Português (Portugal)',
97 'ru': 'Русский язык (Russian)',
101 'sr': 'Cрпски (Serbian)',
103 'szl': 'ślōnskŏ gŏdka',
104 'ta_IN': 'தமிழ் (India)',
105 'te': 'తెలుగు (Telugu)',
106 'th': 'ภาษาไทย (Thai)',
108 'tr': 'Türkçe (Turkish)',
109 'uk': 'Українська (Ukrainian)',
110 'uz': 'Ўзбек тили (Uzbek)',
111 'vi': 'Tiếng Việt (Vietnamese)',
112 'zh': '中文, 汉语, 漢語 (Chinese)',
113 'zh_TW': '臺灣話 Chinese (Taiwan)'}
116 for root
, folders
, filenames
in os
.walk(projectRootDirectory
):
117 for folder
in folders
:
118 if folder
== l10nFolderName
:
119 if os
.path
.exists(os
.path
.join(root
, folder
, transifexClientFolder
)):
120 poLocations
.append(os
.path
.join(root
, folder
))
122 creditsLocation
= os
.path
.join(projectRootDirectory
, 'binaries', 'data', 'mods', 'public', 'gui', 'credits', 'texts', 'translators.json')
124 # This dictionnary will hold creditors lists for each language, indexed by code
127 # Create the new JSON data
128 newJSONData
= {'Title': 'Translators', 'Content': []}
130 # Now go through the list of languages and search the .po files for people
132 # Prepare some regexes
133 translatorMatch
= re
.compile('# (.*)')
134 deletedUsernameMatch
= re
.compile('[0-9a-f]{32}')
137 for lang
in langs
.keys():
138 if lang
not in langsLists
.keys():
139 langsLists
[lang
] = []
141 for location
in poLocations
:
142 files
= glob
.glob(os
.path
.join(location
, lang
+ '.*.po'))
144 poFile
= open(file.replace('\\', '/'), encoding
='utf-8')
148 m
= translatorMatch
.match(line
)
152 username
= m
.group(1)
153 if not deletedUsernameMatch
.match(username
):
154 langsLists
[lang
].append(username
)
155 if line
.strip() == '# Translators:':
159 # Sort and remove duplicates
160 # Sorting should ignore case to have a neat credits list
161 langsLists
[lang
] = sorted(set(langsLists
[lang
]), key
=lambda s
: s
.lower())
163 # Now insert the new data into the new JSON file
164 for (langCode
, langList
) in sorted(langsLists
.items()):
165 newJSONData
['Content'].append({'LangName': langs
[langCode
], 'List': []})
166 for name
in langList
:
167 newJSONData
['Content'][-1]['List'].append({'name': name
})
169 # Save the JSON data to the credits file
170 creditsFile
= open(creditsLocation
, 'w', encoding
='utf-8')
171 json
.dump(newJSONData
, creditsFile
, indent
=4)