diff options
author | Jesusaves <cpntb1@ymail.com> | 2024-08-25 20:09:20 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2024-08-25 20:10:41 -0300 |
commit | 34e709cbd63905dbb5ace2c824c39516289e106e (patch) | |
tree | 718f02fe8a6a397eb1fc846afea2192f6755bace | |
parent | 99a906fd509af96b52bd325c18013ebef9552ee7 (diff) | |
download | tools-34e709cbd63905dbb5ace2c824c39516289e106e.tar.gz tools-34e709cbd63905dbb5ace2c824c39516289e106e.tar.bz2 tools-34e709cbd63905dbb5ace2c824c39516289e106e.tar.xz tools-34e709cbd63905dbb5ace2c824c39516289e106e.zip |
Add helper file which splits a po file into multiple po files.
Objective is making translation easier.
-rwxr-xr-x | ledit/posplit.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/ledit/posplit.py b/ledit/posplit.py new file mode 100755 index 0000000..71a9505 --- /dev/null +++ b/ledit/posplit.py @@ -0,0 +1,67 @@ +#!/usr/bin/python3 +##################################### +## (C) Jesusalva, 2024 +## Published under the MIT License +##################################### + +import traceback, sys, time, os +import polib + +## The file which we're splitting; to merge use msgcat +if len(sys.argv) >= 2: + fn = sys.argv[1] +else: + fn="../for_translation_moubootaur-legends_serverdata_de.po" + +## Open the PO file and report current completion +print("Opening \"%s\"...", fn) +po=polib.pofile(fn) +cnt=0 +print("Current string count: %d" % len(po)) + +domains=("Nard", "Candor", "Databases", "Tonori", "Hurnscald", "LoF", "Academy", "Kaizei", "Frostia", "Events", "Fortress", "Special", "Kamelot", "System", "Other", "Error") + +deeds={} +for d in domains: + deeds[d] = polib.POFile() + deeds[d].metadata = { + 'Project-Id-Version': '1.0', + 'Report-Msgid-Bugs-To': 'admin@tmw2.org', + 'POT-Creation-Date': '1970-01-01 00:00+0000', + 'PO-Revision-Date': '1970-01-01 00:00+0000', + 'Last-Translator': 'Auto Generated <admin@tmw2.org>', + 'Language-Team': 'English <admin@tmw2.org>', + 'MIME-Version': '1.0', + 'Content-Type': 'text/plain; charset=utf-8', + 'Content-Transfer-Encoding': '8bit', +} + +################################################################################# +polist=[]; current="" + +# Use msgcat to merge the po files +# msgcat -o out.po *.po +for entry in po: + found=False + for k in domains: + if "domain/%s" % (k) in repr(entry.occurrences): + deeds[k].append(entry) + found=True + break + if not found: + deeds["Error"].append(entry) + +wc=0; awc=0 +for k in domains: + awc+=wc + wc=0 + for w in deeds[k]: + wc+=len(w.msgid.split()) + print("\033[1m%s\033[0m: %s%% completed, %d strings, %d words" % (k, str(deeds[k].percent_translated()), len(deeds[k]), wc)) + if wc > 0: + deeds[k].save('domain_%s.po' % k) + else: + print("\033[31;1m%s was not saved.\033[0m" % k) + +awc += wc; wc = 0 +print("Finished with %d words total." % awc) |