i18n: find locale dir from the optional configuration file generated by meson

This commit is contained in:
SwimmingTiger 2020-06-18 03:51:45 +08:00 committed by Mathieu Comandon
parent 00ee415eb8
commit 40348f9fe0
3 changed files with 36 additions and 9 deletions

View file

@ -33,19 +33,28 @@ except locale.Error:
sys.stderr.write("Unsupported locale setting. Fix your locales\n")
try:
# Application install prefix
# Example:
# /usr/bin/lutris/../.. -> /usr
# $HOME/.local/bin/lutris/../.. -> $HOME/.local
prefixPath = os.path.realpath(os.path.join(__file__, os.path.pardir, os.path.pardir))
# optional_settings does not exist if you don't use the meson build system
from lutris import optional_settings
localDir = "%s/share/locale" % prefixPath
locale.bindtextdomain("lutris", localDir)
try:
locale.bindtextdomain("lutris", optional_settings.LOCALE_DIR)
gettext.bindtextdomain("lutris", optional_settings.LOCALE_DIR)
except:
sys.stderr.write(
"Couldn't bind gettext domain, translations may not work.\n"
"LOCALE_DIR: %s\n" % optional_settings.LOCALE_DIR
)
except:
sys.stderr.write(
"Unable to load optional_settings, locale dir is not set, "
"translations may not work.\n"
)
try:
locale.textdomain("lutris")
gettext.bindtextdomain("lutris", localDir)
gettext.textdomain("lutris")
except:
sys.stderr.write("Couldn't set gettext domain, translations won't work.")
sys.stderr.write("Couldn't set gettext domain, translations won't work.\n")
from lutris.gui.application import Application # pylint: disable=no-name-in-module

View file

@ -26,6 +26,20 @@ bindir = get_option('bindir')
pylibdir = py.get_install_dir()
datadir = get_option('datadir')
localedir = get_option('localedir')
lutrisdir = join_paths(pylibdir, 'lutris')
# Generate configuration files
prefix = get_option('prefix')
config = configuration_data()
config.set('localedir_path', join_paths(prefix, localedir))
configure_file(
input: 'optional_settings.py.in',
output: 'optional_settings.py',
configuration: config,
install: true,
install_dir: lutrisdir,
)
# Translations (see github issue #728)
subdir('po')

4
optional_settings.py.in Normal file
View file

@ -0,0 +1,4 @@
"""Optional configuration automatically generated by the build system"""
# Paths
LOCALE_DIR = "@localedir_path@"