forked from doublespeakgames/adarkroom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01f15f4
commit 93ffadb
Showing
1 changed file
with
38 additions
and
40 deletions.
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 |
---|---|---|
@@ -1,58 +1,56 @@ | ||
#!/usr/bin/python | ||
# | ||
# convert .po to .js | ||
# | ||
"""convert .po to .js file.""" | ||
|
||
import json | ||
import optparse | ||
import os | ||
import polib | ||
import re | ||
import string | ||
import sys | ||
|
||
parser = optparse.OptionParser(usage="usage: %prog [options] pofile...") | ||
parser.add_option("--callback", default="_.setTranslation", dest="callback", help="callback function to call with data") | ||
parser.add_option("--quiet", action="store_false", default=True, dest="verbose", help="don't print status messages to stdout") | ||
parser.add_option("--callback", default="_.setTranslation", dest="callback", | ||
help="callback function to call with data") | ||
parser.add_option("--quiet", action="store_false", default=True, | ||
dest="verbose", help="don't print status messages to stdout") | ||
|
||
(options, args) = parser.parse_args() | ||
|
||
if args == None or len(args) == 0: | ||
print("ERROR: you must specify at least one po file to translate"); | ||
sys.exit(1) | ||
if args is None or len(args) == 0: | ||
print("ERROR: you must specify at least one po file to translate") | ||
sys.exit(1) | ||
|
||
paramFix = re.compile("(\\(([0-9])\\))") | ||
|
||
for srcfile in args: | ||
|
||
destfile = os.path.splitext(srcfile)[0] + ".js" | ||
if options.verbose: | ||
print("INFO: converting %s to %s" % (srcfile, destfile)) | ||
|
||
xlate_map = {} | ||
|
||
po = polib.pofile(srcfile, autodetect_encoding=False, encoding="utf-8", wrapwidth=-1) | ||
for entry in po: | ||
if entry.obsolete or entry.msgstr == '' or entry.msgstr == entry.msgid: | ||
continue | ||
|
||
xlate_map[entry.msgid] = entry.msgstr; | ||
|
||
dest = open(destfile, "w") | ||
|
||
dest.write(options.callback); | ||
dest.write("("); | ||
|
||
encoder = json.JSONEncoder() | ||
|
||
for part in encoder.iterencode(xlate_map): | ||
if part.startswith('"function('): | ||
dest.write(part[1:-1]); | ||
else: | ||
dest.write(part); | ||
|
||
dest.write(");\n") | ||
|
||
dest.close() | ||
|
||
|
||
destfile = os.path.splitext(srcfile)[0] + ".js" | ||
if options.verbose: | ||
print("INFO: converting %s to %s" % (srcfile, destfile)) | ||
|
||
xlate_map = {} | ||
|
||
po = polib.pofile(srcfile, autodetect_encoding=False, | ||
encoding="utf-8", wrapwidth=-1) | ||
for entry in po: | ||
if entry.obsolete or entry.msgstr == '' or entry.msgstr == entry.msgid: | ||
continue | ||
|
||
xlate_map[entry.msgid] = entry.msgstr | ||
|
||
dest = open(destfile, "w") | ||
|
||
dest.write(options.callback) | ||
dest.write("(") | ||
|
||
encoder = json.JSONEncoder() | ||
|
||
for part in encoder.iterencode(xlate_map): | ||
if part.startswith('"function('): | ||
dest.write(part[1:-1]) | ||
else: | ||
dest.write(part) | ||
|
||
dest.write(");\n") | ||
|
||
dest.close() |