forked from pewpewlive/ppl-i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_readme.py
executable file
·88 lines (80 loc) · 3.83 KB
/
generate_readme.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import datetime
import json
import sys
# Change CWD to the script's own director.
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
# Notes about metadata.json (can't put comments in json!):
# * the order in which the languages are is:
# - sort-of latin-based languages first, in alphabetical order
# - followed by the other real languages, in alphabetical order
# - the fun languages, in alphabetical order
# * language code are (when possible) in ISO 639-2
# https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
# * There is no code for the chinese variants
# * TODO: rename "gre" into "ell", as per wikipedia
metadata_source_file_path = "metadata.json"
with open(metadata_source_file_path, 'r', encoding='utf8') as f:
langs = json.load(f)
lang_files_dir = "translations/"
lang_stats = {}
# Generate the stats
for lang in langs:
print("parsing " + lang["english_name"])
lang_code = lang["code"]
lang_file = lang_files_dir + lang_code + ".po"
message_count = 0.0
missing_translations = 0.0
with open(lang_file, 'r', encoding="utf8") as f:
for line in f:
if line.startswith("msgstr"):
message_count += 1
if line == "msgstr \"\"\n":
missing_translations += 1
lang_stats[lang_code] = {"total": message_count,
"missing": missing_translations}
f.close()
# Write the README
readme_file = "README.md"
with open(readme_file, 'w', encoding="utf8", newline='\n') as f:
f.write("[//]: # \"This file is automatically generated by " +
os.path.basename(__file__) + "\"\n")
f.write("# ppl-i18n\n")
f.write("This repository contains the translated strings for the game [PewPew Live](https://pewpew.live).\n")
f.write("## Contributing\n")
f.write("Any contribution helps, even if its only a few words or phrases.\n")
f.write("(but please only contribute to languages you can speak; no Google Translate)\n")
f.write("\n")
f.write("For information on how to submit changes on GitHub, take a look at this [guide](https://docs.github.com/en/free-pro-team@latest/github/managing-files-in-a-repository/editing-files-in-another-users-repository).\n")
f.write("\n")
f.write("If you contribute a significant amount, I'll put you in the credits!\n")
f.write("\n")
f.write("A few tips for contributing:\n")
f.write("* Keep the `%s` as they later get replaced by some other text.\n")
f.write("* The text fragments that look like `#ffffffff` encode colors. Keep them!\n")
f.write("* Try to have the translations be approximately the same length as the English text.\n")
f.write("* Don't hesitate the reword the text to better fit the language.\n")
f.write("* In order to reduce merge conflicts, avoid working on a single pull request for multiple days. It's better if you create one pull request per day.\n")
f.write("## Adding new languages\n")
f.write("If you want to add support for a new language, create a GitHub Issue so that we can discuss\n")
f.write("the feasibility.\n")
f.write("## Status\n")
for lang in langs:
lang_code = lang["code"]
lang_name = lang["english_name"]
stats = lang_stats[lang_code]
percentage = stats["missing"] / stats["total"]
percentage = int(100 - percentage * 100)
comment = " (" + str(percentage) + "% complete; " + \
str(int(stats["missing"])) + " remaining)"
if stats["missing"] == 0:
comment = " (100% complete! 🎉)"
lang_link = "[" + lang_name + "](/translations/" + lang_code + ".po)"
f.write("* " + lang_link + comment + "\n")
date = datetime.datetime.utcnow()
date_str = date.strftime("%b %d %Y %H:%M:%S")
f.write("> Report generated on " + date_str + " UTC")