oxidworks
oxidworks

Reputation: 1642

Set language of GTK Buttons to a different language - Linux - Python

How can I set the default language of the Gtk3 Stock Buttons to another language?

I tried:

sudo apt-get install language-pack-en language-pack-gnome-en

But:

import locale
from pprint import pprint

pprint(locale.getlocale(locale.LC_ALL))
locale.setlocale(locale.LC_ALL, 'en_EN.utf8')

response:

('de_DE', 'UTF-8')
Traceback (most recent call last):
  File "tp_tools.py", line 41, in <module>
    locale.setlocale(locale.LC_ALL, 'en_EN.utf8')
  File "/usr/lib/python2.7/locale.py", line 581, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

Working on Linux Mint 18 with Python 2.7 and Gtk3

Upvotes: 1

Views: 1127

Answers (2)

Bachsau
Bachsau

Reputation: 1325

The problem is that gi.repository.Gtk calls Gtk.init() while being imported, and after that it is nearly impossible to make any changes to localization. Furthermore, setting the locale to hardcoded strings makes your application almost unportable, since the only locale you can assume to exist is "C", which doesn't even include UTF-8 support.

The only solution I found so far is by setting the environment variable 'LANGUAGE' before any import of GLib modules, which is given priority by gettext and does not need to have an encoding definition appended to it (more information). This works for me:

import os
os.environ["LANGUAGE"] = "en"

PS: Stop using Python 2, it's outdated.
PPS: Gtk+ 3 stock buttons are deprecated.

Upvotes: 1

Johnny
Johnny

Reputation: 81

en_EN.utf8 and also en_EN is no valid locale (contrary to de_DE). You can list your installed locales with locale -a in your shell.

A correct locale would be for example en_US or en_GB. And a correct instruction would be locale.setlocale(locale.LC_ALL, 'en_US').

Upvotes: 1

Related Questions