Run a Qt app in a different language?
Asked Answered
P

4

7

I'm working on a Qt application that used to be a KDE application. In the old days, I just had to use some syntax like:

KDELANG=de ./my_app

That ran my_app in German, and only my_app. It might not have been KDELANG, but it was some environment variable like that.

I've spent a ridiculous amount of time trying to coax this answer out of Google, and I give up. There must be some way to run a Qt (4.5 if that matters) application in some other language without switching over my entire locale to get there.

Polynesian answered 9/5, 2009 at 4:20 Comment(1)
how do you know it's not working? Does your app definitely work in German already? Setting the environment KDELANG=de only works if: 1. the app has German content, and 2. the app uses the KDELANG envvar to set the localeWherewithal
L
6

I tried it with the KDE game Kolf and

(export LANG=de_DE.UTF-8; kolf)
(export LANG=en_US.UTF-8; kolf)

did the trick for me to switch it into German or English.

I verified it with the QT application qtparted

(export LANG=de_DE.UTF-8; qtparted)

also comes up in German on my English desktop. Obviously I had to install the German language files to get the translated app working.

Lunetta answered 9/5, 2009 at 4:34 Comment(2)
You can just do: LANG=de_DE.UTF-8 qtparted That will limit the effects to a single application.Eydie
@Matthew The () which create a subshell have the same effect, as the export will only be visible inside the subshell.Lunetta
V
2

Just like any other Linux application, Qt applications follow a rather convoluted way how the application message locale is selected: environment variable LANGUAGE is given preference over LC_ALL, LC_ALL over LC_MESSAGES, LC_MESSAGES over LANG (details).

So any one of the following commands works to change the application's locale for messages, as returned by QLocale::system().name():

LANGUAGE=de ./my_app
LANGUAGE=   LC_ALL=de ./my_app
LANGUAGE=   LC_ALL=   LC_MESSAGES=de ./my_app
LANGUAGE=   LC_ALL=   LC_MESSAGES=   LANG=de   ./my_app

Notes:

  • I tested this with Qt 5.12 under Lubuntu 19.10 (means, using the LXQt desktop).

  • It is entirely up to the Qt application how to adapt to the application locale as returned by QLocale::system(). It may not evaluate QLocale::system() at all, or fail to find its translation files etc..

  • You can also give the above commands in the form env LANGUAGE=de ./application. The env command has some more options to control which environment its child process will see.

  • The locale values specified in the environment variables (here de) do not have to correspond to any locale that is installed system-wide and listed in locale -a.

  • When specifying only a language (like de), Qt will automatically expand it with a default country and return that in QLocale::system().name(), for example de_DE.

  • When specifying a wrong value (such as xy), Qt will return the default C locale from QLocale::system().name().

Vindicable answered 26/7, 2020 at 18:9 Comment(0)
P
0

OK, it's a long story, but it turns out the translations are, in fact, busted, and that's the whole underlying problem here. The obvious thing I tried first works fine. Since this isn't KDE, I just used plain:

LANG=de ./my_app

Now that I've fixed the bug in the debugging code (oh, the irony) I can plainly see that the translation files (which do exist) aren't getting loaded. Ah. Alrighty then. Carry on. Nothing to see here.

Polynesian answered 10/5, 2009 at 1:30 Comment(0)
W
-1

If you are using plasma desktop, install language package from under System Setting -> locale and run app as follow : KDE_LANG=fr ./appName fr represents french, you can choose language of your interest.

Weaver answered 12/9, 2013 at 18:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.