summaryrefslogtreecommitdiff
path: root/lang
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-04-22 19:24:06 +0300
committerAndrei Karas <akaras@inbox.ru>2011-04-22 19:24:06 +0300
commit5756751493ac58a676195112efc4794cca97275a (patch)
tree7f06da9598b4d028c3207587bdbf074e07cf9123 /lang
parent6b128bdae1d04358962c5634b364b3cef95324e5 (diff)
downloadevol-tools-5756751493ac58a676195112efc4794cca97275a.tar.gz
evol-tools-5756751493ac58a676195112efc4794cca97275a.tar.bz2
evol-tools-5756751493ac58a676195112efc4794cca97275a.tar.xz
evol-tools-5756751493ac58a676195112efc4794cca97275a.zip
Add ability to convert language files to and from po files.
Diffstat (limited to 'lang')
-rwxr-xr-xlang/converttopo.py88
-rw-r--r--lang/new/.placeholder0
-rw-r--r--lang/po/.gitignore1
-rwxr-xr-xlang/updatelang.py44
4 files changed, 133 insertions, 0 deletions
diff --git a/lang/converttopo.py b/lang/converttopo.py
new file mode 100755
index 0000000..dc746bd
--- /dev/null
+++ b/lang/converttopo.py
@@ -0,0 +1,88 @@
+#! /usr/bin/env python2.6
+# -*- coding: utf8 -*-
+#
+# Copyright (C) 2011 Evol Online
+# Author: Andrei Karas (4144)
+
+import os
+import re
+
+defaultLang = "en"
+filt = re.compile(".+[.]txt", re.IGNORECASE)
+
+allStrings = set()
+strre1 = re.compile("[\t +(]l[(][\"](?P<str>[^\"]+)[\"]")
+strre3 = re.compile("[\t +(]getitemlink[(][\"](?P<str>[^\"]+)[\"][)]")
+strre2 = re.compile("^[^/](.+)[.]gat([^\t]+)[\t](script|shop)[\t](?P<str>[\w ]+)[\t]([\d]+),")
+
+langFiles = dict()
+oldLangFiles = dict()
+langs = set()
+itemNamesByName = dict()
+
+
+def loadFiles(dir):
+ with open(dir + "/langs.txt", "r") as f:
+ for line in f:
+ langs.add(line[:-1])
+
+ for file in langs:
+ langFiles[file] = parseFile(dir + "/lang_" + file + ".txt", True)
+
+def parseFile(name, readFirstLine):
+ trans = dict()
+ firstLine = None
+ if os.path.exists(name):
+ with open(name, "r") as f:
+ line1 = "";
+ line2 = "";
+ for line in f:
+ if readFirstLine is True and firstLine is None:
+ firstLine = line
+ continue
+
+ if (line == ""):
+ line1 = ""
+ line2 = ""
+ continue
+ elif (line1 == ""):
+ line1 = line[:-1]
+ continue
+
+ line2 = line[:-1]
+ trans[line1] = line2
+ line1 = ""
+ line2 = ""
+ return (trans, firstLine)
+
+
+def saveFiles(name):
+ for filen in langFiles:
+ saveFile(name, filen)
+
+
+def saveFile(path, name):
+ print str(name)
+ with open (path + "/" + name + ".po", "w") as w:
+ lang = langFiles[name]
+ w.write ("# " + lang[1] + "")
+ w.write ("#\n\n")
+ w.write ("msgid \"\"\n")
+ w.write ("msgstr \"\"\n")
+ w.write ("\"Project-Id-Version: EvolOnline\\n\"\n")
+ w.write ("\"MIME-Version: 1.0\\n\"\n")
+ w.write ("\"Content-Type: text/plain; charset=UTF-8\\n\"\n")
+ w.write ("\"Content-Transfer-Encoding: 8bit\\n\"\n")
+ w.write ("\n")
+ for line in lang[0].keys():
+ line2 = line.replace("\"", "\\\"")
+ w.write ("msgid \"" + line2 + "\"\n")
+ line2 = lang[0][line].replace("\"", "\\\"")
+ w.write ("msgstr \"" + line2 + "\"\n\n")
+
+
+rootPath = "../../gittorious/serverdata"
+
+loadFiles(rootPath + "/langs")
+saveFiles("po")
+
diff --git a/lang/new/.placeholder b/lang/new/.placeholder
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/lang/new/.placeholder
diff --git a/lang/po/.gitignore b/lang/po/.gitignore
new file mode 100644
index 0000000..6d609ce
--- /dev/null
+++ b/lang/po/.gitignore
@@ -0,0 +1 @@
+*.po
diff --git a/lang/updatelang.py b/lang/updatelang.py
index 41a96eb..a0ccda4 100755
--- a/lang/updatelang.py
+++ b/lang/updatelang.py
@@ -84,6 +84,49 @@ def parseFile(name, readFirstLine):
return (trans, firstLine)
+def loadPoFiles(podir):
+ files = os.listdir(podir)
+ for name in files:
+ parsePoFile(name[:-3], podir + "/" + name)
+
+
+def parsePoFile(name, path):
+ langFile = langFiles[name][0]
+ with open(path, "r") as f:
+ flag = 0
+ line1 = ""
+ line2 = ""
+ for line in f:
+ if flag == 0:
+ idx = line.find ("msgid ")
+ if idx == 0:
+ line2 = ""
+ line1 = line[len("msgid "):]
+ line1 = line1[1:len(line1) - 2]
+ flag = 1
+ elif flag == 1:
+ idx = line.find ("msgstr ")
+ if idx == 0:
+ line2 = line[len("msgstr "):]
+ line2 = line2[1:len(line2) - 2]
+ flag = 2
+ if line == "\n":
+ if flag == 2:
+ if line1 != "":
+ if line1 in langFile:
+ langFile[line1] = line2
+ flag = 0
+
+ idx = line.find ("\"")
+ if idx == 0:
+ line = line[1:len(line) - 2]
+ if flag == 1:
+ line1 = line1 + line
+ elif flag == 2:
+ line2 = line2 + line
+
+
+
def addMissingLines():
for trans in langFiles:
newFile = langFiles[trans][0]
@@ -156,5 +199,6 @@ loadItemDb(rootPath + "/db")
collectStrings(rootPath + "/npc")
loadFiles(rootPath + "/langs")
addMissingLines()
+loadPoFiles("new");
sorting()
saveFiles(rootPath + "/langs")