[Interest] problem with localising qt application
Bo Thorsen
bo at fioniasoftware.dk
Wed Feb 29 10:03:23 CET 2012
Den 29-02-2012 09:36, Pritam skrev:
> I am trying to make my application localisation aware. I looked at qt
> examples.
> They all write user visible text inline with the code.
> eg:
>
> label->setText(tr("some long text"));
>
> I dont want to embed user texts in source files because sometimes they
> are very long.
I don't understand the problem. Are you stuck on 80 char monochrome
displays?
Seriously, just put them in there. It doesn't matter how long they are.
> It will be better if I can read all user visible text from a file and
> store them in variables. Rest of the source code uses these variables
> when it needs text.
> eg:
>
> label->setText(tr(UserTexts::categoryLabelText));
>
> But tr() doesn't recognise it. From documentation I can't figure out any
> easy way to do that. Unless I check the current language at startup and
> read appropriate version of my file for that language. But in that case
> I don't get any benefit of Qt Linguist.
If you want to use linguist, you have to use tr("my text") - so the text
has to be in the code. You can store it in a separate file and use
setText(UserTexts::categoryLabelText) and in that file use the tr system
to translate the text.
If you want to have a separate text file with the strings, you're on
your own. Qt does not support this. But making a tr replacement should
not take a long time, so I don't see the problem. Linguist is the nice
part of the Qt i18n system, not tr.
If your text file "happens" to be the native format of linguist, then
you could still use it. I've done this in a PHP project some years ago.
With this idea, you read the file at runtime and grab the translated
strings from it yourself.
Bo Thorsen,
Fionia Software.
--
Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk
More information about the Interest
mailing list