2023-10-02 07:00:29 -05:00
|
|
|
#!/usr/bin/env python3
|
2018-01-02 16:21:11 -06:00
|
|
|
# -*- 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
|
|
|
|
|
2020-10-11 06:24:57 -05:00
|
|
|
|
2018-01-02 16:21:11 -06:00
|
|
|
def usageAndExit():
|
|
|
|
message = """usage: {program} online_dir lo_translations_dir
|
|
|
|
|
|
|
|
Translates style names, layout names, language names, etc. from
|
|
|
|
LibreOffice files.
|
|
|
|
|
|
|
|
"""
|
2020-10-11 06:24:57 -05:00
|
|
|
print(message.format(program=os.path.basename(sys.argv[0])))
|
2018-01-02 16:21:11 -06:00
|
|
|
exit(1)
|
|
|
|
|
|
|
|
# extract translations from po files
|
2020-10-11 06:24:57 -05:00
|
|
|
|
|
|
|
|
2018-01-02 16:21:11 -06:00
|
|
|
def extractFromPo(poFile, stringIds, translations):
|
|
|
|
if not os.path.isfile(poFile):
|
|
|
|
return
|
|
|
|
|
2020-10-11 06:24:57 -05:00
|
|
|
po = polib.pofile(
|
|
|
|
poFile,
|
|
|
|
autodetect_encoding=False,
|
|
|
|
encoding="utf-8", wrapwidth=-1)
|
2018-01-02 16:21:11 -06:00
|
|
|
|
|
|
|
for entry in po.translated_entries():
|
|
|
|
for stringId in stringIds:
|
|
|
|
if stringId in entry.msgctxt:
|
|
|
|
translations[entry.msgid] = entry.msgstr
|
|
|
|
|
2020-10-11 06:24:57 -05:00
|
|
|
|
2018-01-02 16:21:11 -06:00
|
|
|
if __name__ == "__main__":
|
|
|
|
if len(sys.argv) != 3:
|
|
|
|
usageAndExit()
|
|
|
|
|
|
|
|
onlineDir = sys.argv[1]
|
|
|
|
translationsDir = sys.argv[2]
|
|
|
|
|
|
|
|
dir = translationsDir + '/source/'
|
|
|
|
|
|
|
|
for lang in os.listdir(dir):
|
|
|
|
translations = {}
|
|
|
|
|
|
|
|
sys.stderr.write('Generating ' + lang + '...\n')
|
|
|
|
|
2020-10-11 06:24:57 -05:00
|
|
|
# extract 'Clear formatting', shape group names,
|
|
|
|
# and some status bar strings
|
2018-01-02 16:21:11 -06:00
|
|
|
poFile = dir + lang + '/svx/messages.po'
|
2020-10-11 06:24:57 -05:00
|
|
|
extractFromPo(
|
|
|
|
poFile,
|
|
|
|
["RID_SVXSTR_CLEARFORM",
|
|
|
|
"RID_SVXSTR_OVERWRITE_TEXT",
|
|
|
|
"RID_SVXITEMS_PAGE_LAND_TRUE",
|
|
|
|
"RID_SVXITEMS_PAGE_LAND_FALSE",
|
|
|
|
"selectionmenu|",
|
|
|
|
"defaultshapespanel|"], translations)
|
2018-01-02 16:21:11 -06:00
|
|
|
|
|
|
|
# extract Writer style names and status bar strings
|
|
|
|
poFile = dir + lang + '/sw/messages.po'
|
2020-10-11 06:24:57 -05:00
|
|
|
extractFromPo(
|
|
|
|
poFile,
|
|
|
|
["STR_POOL",
|
|
|
|
"STR_PAGE_COUNT",
|
|
|
|
"STR_STATUSBAR_WORDCOUNT_NO_SELECTION",
|
|
|
|
"STR_LANGSTATUS_NONE"], translations)
|
|
|
|
|
|
|
|
# extract Impress/Draw style names,
|
|
|
|
# layout names and 'Slide %1 of %2'
|
2018-01-02 16:21:11 -06:00
|
|
|
poFile = dir + lang + '/sd/messages.po'
|
2020-10-11 06:24:57 -05:00
|
|
|
extractFromPo(
|
|
|
|
poFile,
|
|
|
|
["STR_STANDARD_STYLESHEET_NAME",
|
|
|
|
"STR_POOL", "STR_PSEUDOSHEET",
|
|
|
|
"STR_AUTOLAYOUT",
|
|
|
|
"STR_AL_",
|
|
|
|
"STR_SD_PAGE_COUNT",
|
|
|
|
"drawpagedialog|DrawPageDialog"], translations)
|
2018-01-02 16:21:11 -06:00
|
|
|
|
|
|
|
# extract Calc style names and strings for status bar
|
|
|
|
poFile = dir + lang + '/sc/messages.po'
|
2020-10-11 06:24:57 -05:00
|
|
|
extractFromPo(
|
|
|
|
poFile,
|
|
|
|
["STR_STYLENAME_",
|
|
|
|
"STR_FILTER_SELCOUNT",
|
|
|
|
"STR_ROWCOL_SELCOUNT",
|
|
|
|
"STR_FUN_TEXT_",
|
|
|
|
"STR_UNDO_INSERTCELLS",
|
|
|
|
"STR_TABLE_COUNT"], translations)
|
2018-01-02 16:21:11 -06:00
|
|
|
|
2020-01-21 10:18:16 -06:00
|
|
|
# extract Function Wizard name for formula bar
|
2020-10-11 06:24:57 -05:00
|
|
|
poFile = dir + lang + '/formula/messages.po'
|
2020-01-21 10:18:16 -06:00
|
|
|
extractFromPo(poFile, ["STR_TITLE1"], translations)
|
|
|
|
|
2018-01-02 16:21:11 -06:00
|
|
|
# extract language names
|
|
|
|
poFile = dir + lang + '/svtools/messages.po'
|
|
|
|
extractFromPo(poFile, ["STR_ARR_SVT_LANGUAGE_TABLE"], translations)
|
|
|
|
|
2023-10-02 07:00:29 -05:00
|
|
|
f = open(onlineDir + '/browser/l10n/locore/' + lang + '.json', 'w', encoding='utf-8')
|
2018-01-02 16:21:11 -06:00
|
|
|
f.write('{\n')
|
|
|
|
|
|
|
|
writeComma = False
|
|
|
|
for key in sorted(translations.keys()):
|
|
|
|
if writeComma:
|
|
|
|
f.write(',\n')
|
|
|
|
else:
|
|
|
|
writeComma = True
|
2020-10-11 06:24:57 -05:00
|
|
|
f.write(
|
2023-10-02 07:00:29 -05:00
|
|
|
('"' + key + '":"' + translations[key] + '"'))
|
2018-01-02 16:21:11 -06:00
|
|
|
|
|
|
|
f.write('\n}\n')
|
|
|
|
|
|
|
|
# vim: set shiftwidth=4 softtabstop=4 expandtab:
|