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()
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 …and you beat ChatGPT which got itself into a right tangle.
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.