[Tutor] Pay-at-Pump Use Case - Tkinter GUI

Alan Gauld alan.gauld at yahoo.co.uk
Mon Mar 2 14:26:33 EST 2020


On 02/03/2020 17:51, Jon Davies wrote:
> Hi Alan,
> 
> I've been having a look into internationalization / i18n , and trying to have a play to get a simple example working, however I admit I am struggling.
> 
> 
> My basic test file (translation.py) is stored in a folder Translation, with the structure as follows:
> 
> ./Translation
>             /translation.py,translation.pot
              /locales/de/LC_MESSAGES/translation.mo,translation.po
> 
> Within 'translation.py' is the following:
> 
> import gettext
> 
> de = gettext.translation('translation', localedir='locales', languages=['de'])
> de.install()

I normally use a slightly different preamble:

#################
import gettext

filename = "locales/de/LC_MESSAGES/translation.mo"

trans = gettext.GNUTranslateions(open(filename, 'rb')  # NB. binary!
trans.install()
##################

Actually I'd use a different setup for the files but I'm
guessing you are following a tutorial somewhere?

This creates the GNUTranslations object directly using the
translation file object as an argument.

> def print_some_strings():
>     print(_('Hello world!'))
>     print(_('This is hopefully going to translate!'))
>     print(_('Hooray!'))
> 
> if __name__ == '__main__':
>     print_some_strings()

> I'm confused as I'm pretty certain I've laid everything out correctly. 
> If I can't get a simple example working god knows how I'll apply this in my app!

Offline I'll send you the full text from this section of my
book. It contains the full code and translation file content
plus step by step instructions. See if it helps.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list