pep8 coding style conformance for scripts/untranslated.py
Change-Id: I4a3d8db37ba013b581eeec8fff8fba6fe1bcc966
This commit is contained in:
parent
1b74e1aa67
commit
5f482e57fd
1 changed files with 66 additions and 17 deletions
|
@ -12,27 +12,34 @@ import sys
|
|||
import itertools
|
||||
import re
|
||||
|
||||
|
||||
def usageAndExit():
|
||||
message = """usage: {program} online_dir lo_translations_dir lang
|
||||
|
||||
Prints en-US strings that do not have translations in the specified language.
|
||||
|
||||
"""
|
||||
print(message.format(program = os.path.basename(sys.argv[0])))
|
||||
print(message.format(program=os.path.basename(sys.argv[0])))
|
||||
exit(1)
|
||||
|
||||
|
||||
# extract translations from po files
|
||||
def extractFromPo(poFile, stringIds, untranslated):
|
||||
if not os.path.isfile(poFile):
|
||||
return
|
||||
|
||||
po = polib.pofile(poFile, autodetect_encoding=False, encoding="utf-8", wrapwidth=-1)
|
||||
po = polib.pofile(poFile,
|
||||
autodetect_encoding=False,
|
||||
encoding="utf-8",
|
||||
wrapwidth=-1)
|
||||
|
||||
for entry in itertools.chain(po.untranslated_entries(), po.fuzzy_entries()):
|
||||
for entry in itertools.chain(po.untranslated_entries(),
|
||||
po.fuzzy_entries()):
|
||||
for stringId in stringIds:
|
||||
if stringId in entry.msgctxt:
|
||||
untranslated.append(entry.msgid)
|
||||
|
||||
|
||||
# Read the uno commands present in the unocommands.js for checking
|
||||
def parseUnocommandsJS(onlineDir):
|
||||
strings = {}
|
||||
|
@ -51,12 +58,14 @@ def parseUnocommandsJS(onlineDir):
|
|||
|
||||
return strings
|
||||
|
||||
|
||||
# Remove duplicates from list
|
||||
def uniq(seq):
|
||||
seen = set()
|
||||
seen_add = seen.add
|
||||
return [x for x in seq if not (x in seen or seen_add(x))]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 4:
|
||||
usageAndExit()
|
||||
|
@ -73,19 +82,42 @@ if __name__ == "__main__":
|
|||
|
||||
# extract 'Clear formatting' and some status bar strings
|
||||
poFile = dir + lang + '/svx/messages.po'
|
||||
extractFromPo(poFile, ["RID_SVXSTR_CLEARFORM", "RID_SVXSTR_OVERWRITE_TEXT", "selectionmenu|"], untranslated)
|
||||
extractFromPo(poFile,
|
||||
["RID_SVXSTR_CLEARFORM",
|
||||
"RID_SVXSTR_OVERWRITE_TEXT",
|
||||
"selectionmenu|"],
|
||||
untranslated)
|
||||
|
||||
# extract Writer style names and status bar strings
|
||||
poFile = dir + lang + '/sw/messages.po'
|
||||
extractFromPo(poFile, ["STR_POOL", "STR_PAGE_COUNT", "STR_STATUSBAR_WORDCOUNT_NO_SELECTION", "STR_LANGSTATUS_NONE"], untranslated)
|
||||
extractFromPo(poFile,
|
||||
["STR_POOL",
|
||||
"STR_PAGE_COUNT",
|
||||
"STR_STATUSBAR_WORDCOUNT_NO_SELECTION",
|
||||
"STR_LANGSTATUS_NONE"],
|
||||
untranslated)
|
||||
|
||||
# extract Impress/Draw style names, layout names and 'Slide %1 of %2'
|
||||
poFile = dir + lang + '/sd/messages.po'
|
||||
extractFromPo(poFile, ["STR_STANDARD_STYLESHEET_NAME", "STR_POOL", "STR_PSEUDOSHEET", "STR_AUTOLAYOUT", "STR_AL_", "STR_SD_PAGE_COUNT"], untranslated)
|
||||
extractFromPo(poFile,
|
||||
["STR_STANDARD_STYLESHEET_NAME",
|
||||
"STR_POOL",
|
||||
"STR_PSEUDOSHEET",
|
||||
"STR_AUTOLAYOUT",
|
||||
"STR_AL_",
|
||||
"STR_SD_PAGE_COUNT"],
|
||||
untranslated)
|
||||
|
||||
# extract Calc style names and strings for status bar
|
||||
poFile = dir + lang + '/sc/messages.po'
|
||||
extractFromPo(poFile, ["STR_STYLENAME_", "STR_FILTER_SELCOUNT", "STR_ROWCOL_SELCOUNT", "STR_FUN_TEXT_", "STR_UNDO_INSERTCELLS", "STR_TABLE_COUNT"], untranslated)
|
||||
extractFromPo(poFile,
|
||||
["STR_STYLENAME_",
|
||||
"STR_FILTER_SELCOUNT",
|
||||
"STR_ROWCOL_SELCOUNT",
|
||||
"STR_FUN_TEXT_",
|
||||
"STR_UNDO_INSERTCELLS",
|
||||
"STR_TABLE_COUNT"],
|
||||
untranslated)
|
||||
|
||||
# extract language names
|
||||
poFile = dir + lang + '/svtools/messages.po'
|
||||
|
@ -96,33 +128,50 @@ if __name__ == "__main__":
|
|||
parsed = parseUnocommandsJS(onlineDir)
|
||||
keys = set(parsed.keys())
|
||||
|
||||
poFile = dir + lang + '/officecfg/registry/data/org/openoffice/Office/UI.po'
|
||||
poFile = (dir
|
||||
+ lang
|
||||
+ '/officecfg/registry/data/org/openoffice/Office/UI.po')
|
||||
|
||||
po = polib.pofile(poFile, autodetect_encoding=False, encoding="utf-8", wrapwidth=-1)
|
||||
po = polib.pofile(poFile,
|
||||
autodetect_encoding=False,
|
||||
encoding="utf-8",
|
||||
wrapwidth=-1)
|
||||
|
||||
for entry in itertools.chain(po.untranslated_entries(), po.fuzzy_entries()):
|
||||
for entry in itertools.chain(po.untranslated_entries(),
|
||||
po.fuzzy_entries()):
|
||||
m = re.search(r"\.uno:([^\n]*)\n", entry.msgctxt)
|
||||
if m:
|
||||
command = m.group(1)
|
||||
if command in keys:
|
||||
for text in parsed[command]:
|
||||
if text == entry.msgid:
|
||||
untranslated.append(entry.msgid.replace("~",""))
|
||||
untranslated.append(entry.msgid.replace("~", ""))
|
||||
|
||||
# Online UI
|
||||
|
||||
poFile = onlineDir + '/loleaflet/po/ui-' + lang.replace("-","_") + '.po'
|
||||
po = polib.pofile(poFile, autodetect_encoding=False, encoding="utf-8", wrapwidth=-1)
|
||||
poFile = onlineDir + '/loleaflet/po/ui-' + lang.replace("-", "_") + '.po'
|
||||
po = polib.pofile(poFile,
|
||||
autodetect_encoding=False,
|
||||
encoding="utf-8",
|
||||
wrapwidth=-1)
|
||||
|
||||
for entry in itertools.chain(po.untranslated_entries(), po.fuzzy_entries()):
|
||||
for entry in itertools.chain(po.untranslated_entries(),
|
||||
po.fuzzy_entries()):
|
||||
untranslated.append(entry.msgid)
|
||||
|
||||
# Online help (keyboard shortcuts)
|
||||
|
||||
poFile = onlineDir + '/loleaflet/po/help-' + lang.replace("-","_") + '.po'
|
||||
po = polib.pofile(poFile, autodetect_encoding=False, encoding="utf-8", wrapwidth=-1)
|
||||
poFile = (onlineDir
|
||||
+ '/loleaflet/po/help-'
|
||||
+ lang.replace("-", "_")
|
||||
+ '.po')
|
||||
po = polib.pofile(poFile,
|
||||
autodetect_encoding=False,
|
||||
encoding="utf-8",
|
||||
wrapwidth=-1)
|
||||
|
||||
for entry in itertools.chain(po.untranslated_entries(), po.fuzzy_entries()):
|
||||
for entry in itertools.chain(po.untranslated_entries(),
|
||||
po.fuzzy_entries()):
|
||||
untranslated.append(entry.msgid)
|
||||
|
||||
# Print the results
|
||||
|
|
Loading…
Reference in a new issue