From 6bdb666b5f12cc1fe39f4c7d585246cc1da30ff7 Mon Sep 17 00:00:00 2001 From: Balthasar Reuter Date: Thu, 23 Aug 2018 17:24:15 +0200 Subject: [PATCH] Added working i18n --- MANIFEST.in | 4 +++- photobooth/main.py | 2 +- setup.py | 36 ++++++++++++++++++++++++++++-------- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index ec8acc1..9412c6c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,5 @@ include *.md include LICENSE.txt -recursive-include photobooth *.cfg \ No newline at end of file +recursive-include photobooth *.cfg +recursive-include photobooth/locale *.po +recursive-include photobooth/locale *.mo diff --git a/photobooth/main.py b/photobooth/main.py index eacd5f8..63ddd7b 100644 --- a/photobooth/main.py +++ b/photobooth/main.py @@ -39,7 +39,7 @@ from .Threading import Communicator, Workers from .worker import Worker # Globally install gettext for I18N -gettext.install('photobooth') +gettext.install('photobooth', 'photobooth/locale') class CameraProcess(mp.Process): diff --git a/setup.py b/setup.py index 2f2481f..e5054fe 100644 --- a/setup.py +++ b/setup.py @@ -27,20 +27,34 @@ with relevant changes in place. from setuptools import setup, find_packages # To use a consistent encoding from codecs import open -from os import path +from os import path, listdir # To compile message catalogs from setuptools.command.sdist import sdist +from distutils.command.build import build here = path.abspath(path.dirname(__file__)) -class Sdist(sdist): - """Custom ``sdist`` command to ensure that mo files are always created.""" +class CustomBuild(build): + """Custom ``build`` class to include additional build steps.""" - def run(self): - self.run_command('compile_catalog') - # sdist is an old style class so super cannot be used. - sdist.run(self) + sub_commands = [ + ('compile_catalog', None), # Run ``compile_catalog`` to create mo files + ] + build.sub_commands + + +def get_mo_files(basedir, installdir): + """Function to find all the .mo files for installation.""" + + data_files = [] + + for d in listdir(basedir): + if path.isdir(path.join(basedir, d)): + data_files.append((path.join(installdir, d, 'LC_MESSAGES'), + [path.join(basedir, d, 'LC_MESSAGES', + 'photobooth.mo')])) + + return data_files # Get the long description from the README file @@ -208,7 +222,9 @@ setup( # # In this case, 'data_file' will be installed into '/my_data' # data_files=[('my_data', ['data/data_file'])], # Optional - + data_files=[] + + get_mo_files(path.join(here, 'photobooth', 'locale'), + path.join('usr', 'share', 'locale')), # To provide executable scripts, use entry points in preference to the # "scripts" keyword. Entry points provide cross-platform support and allow @@ -236,4 +252,8 @@ setup( 'Bug Reports': 'https://github.com/reuterbal/photobooth/issues', 'Source': 'https://github.com/reuterbal/photobooth/', }, + + cmdclass={ + 'build': CustomBuild, + }, )