54 lines
1.5 KiB
Python
Executable File
54 lines
1.5 KiB
Python
Executable File
#!/usr/bin/python
|
|
# -*- encoding: utf-8 -*-
|
|
import fnmatch
|
|
import polib
|
|
import re
|
|
import os
|
|
import string
|
|
|
|
start_directory = '../..'
|
|
language_filename = '*.pot'
|
|
|
|
search_replace_regex = [
|
|
]
|
|
|
|
search_module = False # ['sale', 'stock']
|
|
|
|
valid_entries = []
|
|
|
|
for root, dirs, files in os.walk(start_directory):
|
|
for filename in fnmatch.filter(files, language_filename):
|
|
print filename
|
|
src = os.path.join(root, filename)
|
|
try:
|
|
po = polib.pofile(src)
|
|
except IOError as e:
|
|
print "ERROR", e
|
|
continue
|
|
for e in po:
|
|
if not e.obsolete:
|
|
valid_entries.append(e)
|
|
|
|
|
|
po2 = polib.POFile()
|
|
|
|
cnt = 0
|
|
for se in search_replace_regex:
|
|
for entry in valid_entries:
|
|
module = re.search(u'(module:)(.*)', entry.comment)
|
|
if module:
|
|
module = module.group(2).strip()
|
|
if search_module is False or module in search_module:
|
|
if re.search(se[0], entry.msgstr):
|
|
entry.msgstr = string.replace(entry.msgstr, se[0], se[1])
|
|
po2.append(entry)
|
|
cnt += 1
|
|
print entry.msgid, "<->", entry.msgstr, cnt
|
|
elif re.search(se[0], entry.msgid):
|
|
entry.msgstr = se[1]
|
|
po2.append(entry)
|
|
cnt += 1
|
|
print entry.msgid, "<->", entry.msgstr, cnt
|
|
|
|
po2.save('../../setup/auto_translated3.po')
|