GTK4 Change language of about-dialog built-in phrases

Myapp is internationalised using gettext, some of the code is below. This works fine, and even the text I put on the About dialogue is translated. However it has built-in titles “About” and “Credits” and phrases such as “Created by” and the licence information. In my example (German) the result is:

“Created by ein Roboter
“This program comes with absolutely no warranty.
See the GNU General Public Licence, version 3 or later for details.”

The above built-in phrases need to be translated too. How is this done?

import gettext
import locale

language = locale.getlocale()[0] 
lang_path = '/home/chris/git/locale' # test directory to which gettext adds {language code}/LC_MESSAGES
lang = gettext.translation('myapp', localedir=lang_path, languages=[{language}])
_ = lang.gettext

	def showAbout(action, button):
		message = Gtk.AboutDialog(transient_for=win, modal=True)
		message.set_authors(['A robot'])
		message.set_license_type(Gtk.License.GPL_3_0)
		message.show()

GTK is fully translated into German.

If you set LANG=de_DE.utf8 in the environment, GTK will use its German translation:

image

I’ve just tried
locale.setlocale(locale.LC_ALL, 'de_DE')
and that works fine. My locale is English, so I needed that statement to make the GUI appear in German for testing. I assume that if my locale was German then it would have shown in German automatically. So I don’t need to do anything for the live version - the best answer to a query one could have :slight_smile: …and you beat ChatGPT which got itself into a right tangle.

You need:

locale.setlocale(locale.LC_ALL, '')

to tell the localisation API to use the current system’s locale, otherwise the default is going to be using the C/POSIX locale.

ChatGPT says that defaulting to the C/POSIX locale may not be accurate or appropriate in all cases, so I’ve used .

It’s definitely not appropriate to use the C/POSIX locale in an application, because otherwise people won’t have a localised UI. The only useful thing a C/POSIX locale gives you is a reliable set of non localised messages for tests.

Thanks for the explanation, ‘the C/POSIX locale’ was a new concept to me. I’ve also edited my previous comment to avoid confusion about what I was going to do.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.