-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from LEDfan/sync_trans_script
Add a script to synchronise translations from the English file to the …
- Loading branch information
Showing
3 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
node_modules | ||
web-ext-artifacts | ||
.web-extension-id | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# @copyright Tobia De Koninck | ||
# @copyright Robin Jadoul | ||
# | ||
# This file is part of Keywi. | ||
# Keywi is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Keywi is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# You should have received a copy of the GNU General Public License | ||
# along with Keywi. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
""" | ||
This script synchronises a translated language file with the English one | ||
It will: | ||
- add new keys from `en/message.json` to any other language file | ||
- update descriptions from `en/messages.json` to any other language file | ||
""" | ||
|
||
import os | ||
import os.path | ||
from os.path import join | ||
import json | ||
from collections import OrderedDict | ||
|
||
translations = {} | ||
|
||
|
||
def sync_translation(base_path, base, target_file_name): | ||
added = [] | ||
updated = [] | ||
not_translated = [] | ||
|
||
with open(join(base_path, target_file_name)) as file: | ||
target = json.load(file, object_pairs_hook=OrderedDict) | ||
|
||
for id in sorted(base): | ||
if id not in target: | ||
added.append(id) | ||
target[id] = base[id] | ||
elif target[id]["description"] != base[id]["description"]: | ||
updated.append(id) | ||
target[id]["description"] = base[id]["description"] | ||
|
||
if target[id]["message"] == base[id]["message"]: | ||
not_translated.append(id) | ||
|
||
with open(join(base_path, target_file_name), 'w') as file: | ||
json.dump(target, file, indent=2, ensure_ascii=False) | ||
|
||
return {"added": added, "updated": updated, "nottranslated": not_translated} | ||
|
||
|
||
if __name__ == "__main__": | ||
base_path = os.path.dirname(__file__) | ||
|
||
with open(join(base_path, '_locales', 'en', 'messages.json')) as file: | ||
enTranslation = json.load(file) | ||
|
||
for f in os.listdir(join(base_path, '_locales')): | ||
if f != "en": | ||
stats = sync_translation(base_path, enTranslation, os.path.join("_locales", f, "messages.json")) | ||
|
||
for key in stats["added"]: | ||
print("[" + str(f) + "] Added " + str(key)) | ||
|
||
for key in stats["updated"]: | ||
print("[" + str(f) + "] Updated " + str(key)) | ||
|
||
for key in stats["nottranslated"]: | ||
print("[" + str(f) + "] Needs translation " + str(key)) |