Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-jambi-interest Archive, June 2007
Re: QTranslator problem


Message 1 in thread

Hi,

the translation itself works but now I have a new problem.

I've set the default locale with the following vm parameters:
-Duser.language=en  -Duser.region=GB

And this code

System.out.println("Default locale: " + Locale.getDefault().toString());
QLocale locale = new QLocale();
System.out.println("Current locale: " + locale.name());

produces the following output:

Default locale: en_GB
Current locale: de_DE

So it seems that QLocale doesn't use the locale of the running jvm. This
is not the real problem though since I can work around this with the
following line of code:

QLocale.setDefault(new QLocale(Locale.getDefault().toString()));


What I want to do is use the name of the jvms locale to load the right
language file. My code looks like this:

QLocale locale = new QLocale();
String localeString = locale.name();
QTranslator translator = new QTranslator();

if (!translator.load("stockviewer." + localeString, "classpath:lang/",
"", ".qm"))
    System.out.println("File not found!!!");

The value of localeString is "en_GB". Unfortunately it only finds the
file if I replace localeString with the String "en". But according to
http://doc.trolltech.com/qtjambi-1.0/com/trolltech/qt/core/QTranslator.html#load(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String) it should look for the filename "stockviewer.en.qm", too.


Regards,

Andreas


Message 2 in thread

On Friday 01 June 2007 00:33, Andreas Heck wrote:
> Hi,
>
> the translation itself works but now I have a new problem.
>
Yes, it's only lupdate that is wrong. By getting the new version you should 
not need to change the ts file by hand.

> I've set the default locale with the following vm parameters:
> -Duser.language=en  -Duser.region=GB
>
> And this code
>
> System.out.println("Default locale: " + Locale.getDefault().toString());
> QLocale locale = new QLocale();
> System.out.println("Current locale: " + locale.name());
>
> produces the following output:
>
> Default locale: en_GB
> Current locale: de_DE
>
> So it seems that QLocale doesn't use the locale of the running jvm. This
> is not the real problem though since I can work around this with the
> following line of code:
>
> QLocale.setDefault(new QLocale(Locale.getDefault().toString()));
>

You are right, we are not looking at the JVM's locale settings. This is 
probably something we should improve.

>
> What I want to do is use the name of the jvms locale to load the right
> language file. My code looks like this:
>
> QLocale locale = new QLocale();
> String localeString = locale.name();
> QTranslator translator = new QTranslator();
>
> if (!translator.load("stockviewer." + localeString, "classpath:lang/",
> "", ".qm"))
>     System.out.println("File not found!!!");
>
> The value of localeString is "en_GB". Unfortunately it only finds the
> file if I replace localeString with the String "en". But according to
> http://doc.trolltech.com/qtjambi-1.0/com/trolltech/qt/core/QTranslator.html
>#load(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.
>String) it should look for the filename "stockviewer.en.qm", too.
>
The load function takes these arguments:
load(filename, directory, search_delimiters, suffix)

if you set search_delimiters to "_" and not "" it should be able to do what 
you want. Search_delimiters and suffix should have had correct default values 
("_.", and ".qm"), but currently they get set to "".

Hope this helps.

Thanks for reporting this :-)

Best regards,
	HÃvard F