2018-07-30 16:44:27 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
|
|
|
|
#
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
|
|
|
import polib
|
|
|
|
import sys
|
|
|
|
import itertools
|
|
|
|
import re
|
|
|
|
|
2020-10-12 08:37:09 -05:00
|
|
|
|
2018-07-30 16:44:27 -05:00
|
|
|
def usageAndExit():
|
|
|
|
message = """usage: {program} online_dir lo_translations_dir lang
|
|
|
|
|
|
|
|
Prints en-US strings that do not have translations in the specified language.
|
|
|
|
|
|
|
|
"""
|
2020-10-12 08:37:09 -05:00
|
|
|
print(message.format(program=os.path.basename(sys.argv[0])))
|
2018-07-30 16:44:27 -05:00
|
|
|
exit(1)
|
|
|
|
|
2020-10-12 08:37:09 -05:00
|
|
|
|
2018-07-30 16:44:27 -05:00
|
|
|
# extract translations from po files
|
|
|
|
def extractFromPo(poFile, stringIds, untranslated):
|
|
|
|
if not os.path.isfile(poFile):
|
|
|
|
return
|
|
|
|
|
2020-10-12 08:37:09 -05:00
|
|
|
po = polib.pofile(poFile,
|
|
|
|
autodetect_encoding=False,
|
|
|
|
encoding="utf-8",
|
|
|
|
wrapwidth=-1)
|
2018-07-30 16:44:27 -05:00
|
|
|
|
2020-10-12 08:37:09 -05:00
|
|
|
for entry in itertools.chain(po.untranslated_entries(),
|
|
|
|
po.fuzzy_entries()):
|
2018-07-30 16:44:27 -05:00
|
|
|
for stringId in stringIds:
|
|
|
|
if stringId in entry.msgctxt:
|
|
|
|
untranslated.append(entry.msgid)
|
|
|
|
|
2020-10-12 08:37:09 -05:00
|
|
|
|
2018-07-30 16:44:27 -05:00
|
|
|
# Read the uno commands present in the unocommands.js for checking
|
|
|
|
def parseUnocommandsJS(onlineDir):
|
|
|
|
strings = {}
|
|
|
|
|
2021-11-03 08:43:05 -05:00
|
|
|
f = open(onlineDir + '/browser/src/unocommands.js', 'r')
|
2018-07-30 16:44:27 -05:00
|
|
|
for line in f:
|
|
|
|
line = line.decode('utf-8')
|
|
|
|
m = re.match(r"\t([^:]*):.*", line)
|
|
|
|
if m:
|
|
|
|
command = m.group(1)
|
|
|
|
|
|
|
|
n = re.findall(r"_\('([^']*)'\)", line)
|
|
|
|
if n:
|
|
|
|
strings[command] = n
|
|
|
|
|
|
|
|
return strings
|
|
|
|
|
2020-10-12 08:37:09 -05:00
|
|
|
|
2018-07-30 16:44:27 -05:00
|
|
|
# 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))]
|
|
|
|
|
2020-10-12 08:37:09 -05:00
|
|
|
|
2018-07-30 16:44:27 -05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
if len(sys.argv) != 4:
|
|
|
|
usageAndExit()
|
|
|
|
|
|
|
|
onlineDir = sys.argv[1]
|
|
|
|
translationsDir = sys.argv[2]
|
|
|
|
lang = sys.argv[3]
|
|
|
|
|
|
|
|
dir = translationsDir + '/source/'
|
|
|
|
|
|
|
|
untranslated = []
|
|
|
|
|
|
|
|
# LO Core strings
|
|
|
|
|
2018-10-21 14:22:04 -05:00
|
|
|
# extract 'Clear formatting' and some status bar strings
|
|
|
|
poFile = dir + lang + '/svx/messages.po'
|
2020-10-12 08:37:09 -05:00
|
|
|
extractFromPo(poFile,
|
|
|
|
["RID_SVXSTR_CLEARFORM",
|
|
|
|
"RID_SVXSTR_OVERWRITE_TEXT",
|
|
|
|
"selectionmenu|"],
|
|
|
|
untranslated)
|
2018-10-21 14:22:04 -05:00
|
|
|
|
|
|
|
# extract Writer style names and status bar strings
|
|
|
|
poFile = dir + lang + '/sw/messages.po'
|
2020-10-12 08:37:09 -05:00
|
|
|
extractFromPo(poFile,
|
|
|
|
["STR_POOL",
|
|
|
|
"STR_PAGE_COUNT",
|
|
|
|
"STR_STATUSBAR_WORDCOUNT_NO_SELECTION",
|
|
|
|
"STR_LANGSTATUS_NONE"],
|
|
|
|
untranslated)
|
2018-10-21 14:22:04 -05:00
|
|
|
|
|
|
|
# extract Impress/Draw style names, layout names and 'Slide %1 of %2'
|
|
|
|
poFile = dir + lang + '/sd/messages.po'
|
2020-10-12 08:37:09 -05:00
|
|
|
extractFromPo(poFile,
|
|
|
|
["STR_STANDARD_STYLESHEET_NAME",
|
|
|
|
"STR_POOL",
|
|
|
|
"STR_PSEUDOSHEET",
|
|
|
|
"STR_AUTOLAYOUT",
|
|
|
|
"STR_AL_",
|
|
|
|
"STR_SD_PAGE_COUNT"],
|
|
|
|
untranslated)
|
2018-07-30 16:44:27 -05:00
|
|
|
|
|
|
|
# extract Calc style names and strings for status bar
|
2018-10-21 14:22:04 -05:00
|
|
|
poFile = dir + lang + '/sc/messages.po'
|
2020-10-12 08:37:09 -05:00
|
|
|
extractFromPo(poFile,
|
|
|
|
["STR_STYLENAME_",
|
|
|
|
"STR_FILTER_SELCOUNT",
|
|
|
|
"STR_ROWCOL_SELCOUNT",
|
|
|
|
"STR_FUN_TEXT_",
|
|
|
|
"STR_UNDO_INSERTCELLS",
|
|
|
|
"STR_TABLE_COUNT"],
|
|
|
|
untranslated)
|
2018-07-30 16:44:27 -05:00
|
|
|
|
|
|
|
# extract language names
|
2018-10-21 14:22:04 -05:00
|
|
|
poFile = dir + lang + '/svtools/messages.po'
|
2018-07-30 16:44:27 -05:00
|
|
|
extractFromPo(poFile, ["STR_ARR_SVT_LANGUAGE_TABLE"], untranslated)
|
|
|
|
|
|
|
|
# UNO command strings
|
|
|
|
|
|
|
|
parsed = parseUnocommandsJS(onlineDir)
|
|
|
|
keys = set(parsed.keys())
|
|
|
|
|
2020-10-12 08:37:09 -05:00
|
|
|
poFile = (dir
|
|
|
|
+ lang
|
|
|
|
+ '/officecfg/registry/data/org/openoffice/Office/UI.po')
|
2018-07-30 16:44:27 -05:00
|
|
|
|
2020-10-12 08:37:09 -05:00
|
|
|
po = polib.pofile(poFile,
|
|
|
|
autodetect_encoding=False,
|
|
|
|
encoding="utf-8",
|
|
|
|
wrapwidth=-1)
|
2018-07-30 16:44:27 -05:00
|
|
|
|
2020-10-12 08:37:09 -05:00
|
|
|
for entry in itertools.chain(po.untranslated_entries(),
|
|
|
|
po.fuzzy_entries()):
|
2018-07-30 16:44:27 -05:00
|
|
|
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:
|
2020-10-12 08:37:09 -05:00
|
|
|
untranslated.append(entry.msgid.replace("~", ""))
|
2018-07-30 16:44:27 -05:00
|
|
|
|
|
|
|
# Online UI
|
|
|
|
|
2021-11-03 08:43:05 -05:00
|
|
|
poFile = onlineDir + '/browser/po/ui-' + lang.replace("-", "_") + '.po'
|
2020-10-12 08:37:09 -05:00
|
|
|
po = polib.pofile(poFile,
|
|
|
|
autodetect_encoding=False,
|
|
|
|
encoding="utf-8",
|
|
|
|
wrapwidth=-1)
|
2018-07-30 16:44:27 -05:00
|
|
|
|
2020-10-12 08:37:09 -05:00
|
|
|
for entry in itertools.chain(po.untranslated_entries(),
|
|
|
|
po.fuzzy_entries()):
|
2018-07-30 16:44:27 -05:00
|
|
|
untranslated.append(entry.msgid)
|
|
|
|
|
|
|
|
# Online help (keyboard shortcuts)
|
|
|
|
|
2020-10-12 08:37:09 -05:00
|
|
|
poFile = (onlineDir
|
2021-11-03 08:43:05 -05:00
|
|
|
+ '/browser/po/help-'
|
2020-10-12 08:37:09 -05:00
|
|
|
+ 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()):
|
2018-07-30 16:44:27 -05:00
|
|
|
untranslated.append(entry.msgid)
|
|
|
|
|
|
|
|
# Print the results
|
|
|
|
|
|
|
|
for elem in uniq(untranslated):
|
|
|
|
print elem.encode('utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
# vim: set shiftwidth=4 softtabstop=4 expandtab:
|