summaryrefslogtreecommitdiff
path: root/lang/updatelang.py
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-03-06 17:42:23 +0300
committerAndrei Karas <akaras@inbox.ru>2015-03-06 17:42:23 +0300
commitc41ce0481e85a8095c5ce49a313bca0e9fb55e72 (patch)
treeb2a5cddbb81ff8484b0f8ab95c1b84b1cfa6d3ef /lang/updatelang.py
parent267c987d3a252b272fe7da7cc5e0a3d1e85dc667 (diff)
downloadtools-c41ce0481e85a8095c5ce49a313bca0e9fb55e72.tar.gz
tools-c41ce0481e85a8095c5ce49a313bca0e9fb55e72.tar.bz2
tools-c41ce0481e85a8095c5ce49a313bca0e9fb55e72.tar.xz
tools-c41ce0481e85a8095c5ce49a313bca0e9fb55e72.zip
lang: save in po files files name and line number.
Also save no-c-format attribute.
Diffstat (limited to 'lang/updatelang.py')
-rwxr-xr-xlang/updatelang.py40
1 files changed, 24 insertions, 16 deletions
diff --git a/lang/updatelang.py b/lang/updatelang.py
index eab325d..0da0172 100755
--- a/lang/updatelang.py
+++ b/lang/updatelang.py
@@ -26,55 +26,63 @@ oldLangFiles = dict()
langs = set()
itemNamesByName = dict()
-def addStr(str, comment):
- allStrings.add(str)
+def addStr(text, comment, fileName, lineNum):
+ allStrings.add(text)
if comment[-1:] == "\n":
comment = comment[:-1]
- strComments[str] = comment.strip() + "\n"
+ newComment = "#. code: " + comment.strip() + "\n#: " + fileName + ":" + str(lineNum) + "\n#, no-c-format\n"
+ if text in strComments:
+ strComments[text] = strComments[text] + newComment
+ else:
+ strComments[text] = newComment
-def collectStrings(parentDir):
+def collectStrings(parentDir, relativeDir):
global itemNamesByName
files = os.listdir(parentDir)
for file1 in files:
if file1[0] == ".":
continue
file2 = os.path.abspath(parentDir + os.path.sep + file1)
+ relativeDir2 = relativeDir + os.path.sep + file1
if not os.path.isfile(file2):
- collectStrings(file2)
+ collectStrings(file2, relativeDir2)
elif filt.search(file1):
+ codeFile = relativeDir + os.path.sep + file1
with open(file2, "r") as f:
+ cnt = -1
for line in f:
+ cnt = cnt + 1
m = strre1.findall(line)
if len(m) > 0:
for str in m:
- addStr(str, line)
+ addStr(str, line, codeFile, cnt)
m = strre4.findall(line)
if len(m) > 0:
for str in m:
- addStr(str + "#0", line)
- addStr(str + "#1", line)
+ addStr(str + "#0", line, codeFile, cnt)
+ addStr(str + "#1", line, codeFile, cnt)
m = strre2.search(line)
if m is not None and m.group("str")[0] != "#":
- addStr(m.group("str"), line)
+ addStr(m.group("str"), line, codeFile, cnt)
m = strre3.findall(line)
if len(m) > 0:
for str in m:
if str.lower() in itemNamesByName:
- addStr(itemNamesByName[str.lower()], line)
+ addStr(itemNamesByName[str.lower()], line, codeFile, cnt)
m = strre5.findall(line)
if len(m) > 0:
for str in m:
if str.lower() in itemNamesByName:
- addStr(itemNamesByName[str.lower()], line)
+ addStr(itemNamesByName[str.lower()], line, codeFile, cnt)
m = strre6.findall(line)
if len(m) > 0:
for str in m:
- addStr(str, line)
+ addStr(str, line, codeFile, cnt)
m = strre7.findall(line)
if len(m) > 0:
for str in m:
- addStr(str[0] + "#0", line)
- addStr(str[2] + "#1", line)
+ addStr(str[0] + "#0", line, codeFile, cnt)
+ addStr(str[2] + "#1", line, codeFile, cnt)
@@ -247,7 +255,7 @@ def writePoFile(poDir, texts, trans):
w.write ("\n")
for line in texts[0]:
if line[0] in strComments.keys():
- w.write ("#. code: " + strComments[line[0]])
+ w.write (strComments[line[0]])
w.write ("msgid \"" + line[0].replace("\"", "\\\"") + "\"\n")
trLine = line[1]
@@ -311,7 +319,7 @@ def dumpTranslations():
rootPath = "../../server-data/"
loadItemDb(rootPath + "db/re")
-collectStrings(rootPath + "/npc")
+collectStrings(rootPath + "/npc", "npc")
loadFiles(rootPath + "/langs")
addMissingLines()
loadPoFiles("in");