65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
"""
|
||
|
|
This will generate the .pot and .mo files for the application domain and
|
||
|
|
languages defined below.
|
||
|
|
|
||
|
|
The .po and .mo files are placed as per convention in
|
||
|
|
|
||
|
|
"appfolder/locale/lang/LC_MESSAGES"
|
||
|
|
|
||
|
|
The .pot file is placed in the locale folder.
|
||
|
|
|
||
|
|
This script or something similar should be added to your build process.
|
||
|
|
|
||
|
|
The actual translation work is normally done using a tool like poEdit or
|
||
|
|
similar, it allows you to generate a particular language catalog from the .pot
|
||
|
|
file or to use the .pot to merge new translations into an existing language
|
||
|
|
catalog.
|
||
|
|
|
||
|
|
"""
|
||
|
|
|
||
|
|
import os
|
||
|
|
import subprocess
|
||
|
|
import sys
|
||
|
|
|
||
|
|
import family_register
|
||
|
|
import family_register.app_constants
|
||
|
|
|
||
|
|
# we remove English as source code strings are in English
|
||
|
|
supportedLang = []
|
||
|
|
for l in family_register.app_constants.LANG:
|
||
|
|
if l != family_register.app_constants.LANG.en:
|
||
|
|
supportedLang.append(l.name)
|
||
|
|
|
||
|
|
appFolder = os.path.dirname(os.path.abspath(family_register.__file__))
|
||
|
|
|
||
|
|
# setup some stuff to get at Python I18N tools/utilities
|
||
|
|
|
||
|
|
pyExe = sys.executable
|
||
|
|
pyFolder = '/usr/lib/python3.9' # os.path.split(pyExe)[0]
|
||
|
|
pyToolsFolder = os.path.join(pyFolder, 'Tools')
|
||
|
|
pyI18nFolder = os.path.join(pyToolsFolder, 'i18n')
|
||
|
|
pyGettext = os.path.join(pyI18nFolder, 'pygettext.py')
|
||
|
|
pyMsgfmt = os.path.join(pyI18nFolder, 'msgfmt.py')
|
||
|
|
outFolder = os.path.join(appFolder, 'locale')
|
||
|
|
|
||
|
|
langDomain = family_register.app_constants.LANG_DOMAIN
|
||
|
|
|
||
|
|
# build command for pygettext
|
||
|
|
tCmd = f'{pyExe} -Xutf8 {pyGettext} -a -d {langDomain} -o {langDomain}.pot -p {outFolder} {appFolder}'
|
||
|
|
print("Generating the .pot file")
|
||
|
|
print(f"cmd: {tCmd}")
|
||
|
|
rCode = subprocess.call(tCmd, shell=True)
|
||
|
|
print(f"return code: {rCode}\n\n")
|
||
|
|
|
||
|
|
for tLang in supportedLang:
|
||
|
|
# build command for msgfmt
|
||
|
|
langDir = os.path.join(appFolder, rf'locale\{tLang}\LC_MESSAGES')
|
||
|
|
poFile = os.path.join(langDir, f'{langDomain}.po')
|
||
|
|
tCmd = f'{pyExe} {pyMsgfmt} {poFile}'
|
||
|
|
|
||
|
|
print("Generating the .mo file")
|
||
|
|
print(f"cmd: {tCmd}")
|
||
|
|
rCode = subprocess.call(tCmd, shell=True)
|
||
|
|
print(f"return code: {rCode}\n\n")
|