Added working i18n

This commit is contained in:
Balthasar Reuter
2018-08-23 17:24:15 +02:00
parent c8c3f78216
commit 6bdb666b5f
3 changed files with 32 additions and 10 deletions

View File

@@ -1,3 +1,5 @@
include *.md
include LICENSE.txt
recursive-include photobooth *.cfg
recursive-include photobooth *.cfg
recursive-include photobooth/locale *.po
recursive-include photobooth/locale *.mo

View File

@@ -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):

View File

@@ -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 '<sys.prefix>/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,
},
)