Skip to content

Commit

Permalink
Merge pull request #1101 from hroncok/fix_locale_data
Browse files Browse the repository at this point in the history
Install locale data into nested locations; Pick files from /usr/(local/)share with sys.prefix
  • Loading branch information
kliment authored Sep 6, 2020
2 parents 160db07 + 4c284e8 commit 7abda79
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ To update a previously created message catalog from the template, use :

As currently coded, the default location for these message catalogs is

/usr/share/pronterface/locale/
/usr/share/locale/

So, to install the catalogs, copy them to there:

sudo cp -a locale /usr/share/pronterface/
sudo cp -a locale /usr/share/

To test pronterface in a new language, you can temporarily set LANG to
the language you are testing, for example

LANG=de python pronterface.py
LANG=de.UTF-8 python pronterface.py

Further automation for localization and packaging of Printrun would be
nice to see, but is not here yet.
Expand Down
26 changes: 13 additions & 13 deletions printrun/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import locale
import logging

DATADIR = os.path.join(sys.prefix, 'share')


def set_utf8_locale():
"""Make sure we read/write all text files in UTF-8"""
Expand All @@ -34,10 +36,9 @@ def set_utf8_locale():
# searching for installed locales on /usr/share; uses relative folder if not
# found (windows)
def install_locale(domain):
if os.path.exists('/usr/share/pronterface/locale'):
gettext.install(domain, '/usr/share/pronterface/locale')
elif os.path.exists('/usr/local/share/pronterface/locale'):
gettext.install(domain, '/usr/local/share/pronterface/locale')
shared_locale_dir = os.path.join(DATADIR, 'locale')
if os.path.exists(shared_locale_dir):
gettext.install(domain, shared_locale_dir)
else:
gettext.install(domain, './locale')

Expand Down Expand Up @@ -78,11 +79,10 @@ def iconfile(filename):
return pixmapfile(filename)

def imagefile(filename):
for prefix in ['/usr/local/share/pronterface/images',
'/usr/share/pronterface/images']:
candidate = os.path.join(prefix, filename)
if os.path.exists(candidate):
return candidate
shared_pronterface_images_dir = os.path.join(DATADIR, 'pronterface/images')
candidate = os.path.join(shared_pronterface_images_dir, filename)
if os.path.exists(candidate):
return candidate
local_candidate = os.path.join(os.path.dirname(sys.argv[0]),
"images", filename)
if os.path.exists(local_candidate):
Expand All @@ -105,12 +105,12 @@ def lookup_file(filename, prefixes):
return filename

def pixmapfile(filename):
return lookup_file(filename, ['/usr/local/share/pixmaps',
'/usr/share/pixmaps'])
shared_pixmaps_dir = os.path.join(DATADIR, 'pixmaps')
return lookup_file(filename, [shared_pixmaps_dir])

def sharedfile(filename):
return lookup_file(filename, ['/usr/local/share/pronterface',
'/usr/share/pronterface'])
shared_pronterface_dir = os.path.join(DATADIR, 'pronterface')
return lookup_file(filename, [shared_pronterface_dir])

def configfile(filename):
return lookup_file(filename, [os.path.expanduser("~/.printrun/"), ])
Expand Down
9 changes: 6 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ def multiglob(*globs):
('share/pixmaps', multiglob('*.png')),
('share/applications', multiglob('*.desktop')),
('share/metainfo', multiglob('*.appdata.xml')),
('share/pronterface', multiglob('images/*.png',
'images/*.svg',
'locale/*/LC_MESSAGES/*.mo')),
('share/pronterface/images', multiglob('images/*.png',
'images/*.svg')),
]

for locale in glob.glob('locale/*/LC_MESSAGES/'):
data_files.append((f'share/{locale}', glob.glob(f'{locale}/*.mo')))


setup(
name="Printrun",
version=__version__,
Expand Down

0 comments on commit 7abda79

Please sign in to comment.