How to change the locale at runtime?
I've watched the internationalization part of the Swing GUI Designer Live Demo and implemented an example. Within the GUI Designer I can change the locale from the drop down list and see all of my strings change. This is also reflected when one uses the Preview function.
I've added a combo box to the top right corner of my app with both of my languages, and would like to change the locale in the propertyChanged listener method and have all of my texts change automatically. How is the locale changed at runtime? I've tried setting the default locale but have had no success...
请先登录再写评论。
Hello migueljuan15,
You'll need to implement this by yourself. UI Designer forms initialize the
property values at construction time, and there is no possibility to re-initialize
them later automatically.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Ok, thanks anyway.
Hello,
i have a similar problem. Ive written properties files both in German and in English. My GUI forms use values from these files.
When i switch (in the Windows system settings) from German to English, everything works fine. It´s a quite large application which uses lots of different configuration dialogs.
Now i have the following request: a user on a Windows with German system settings should be able to use this application in English language (without switching the system settings). But how can i do that without writing lots of code (setting the texts via code and not via GUI form designer)?
Is it possible to tell the app somehow that the forms should initialize using gui_en.properties even when the system settings are German?
friendly greetings
Oliver
IIRC, if you launch your java application supplying the property -Duser.language=]]> it should work as you want
Yes, it worked! Thanks a lot :)
Hello,
i know this is an old thread, but i wanted to say that the solution with -Duser.language is not ideal in my opinion, because it overwrites the language
used for Locale.getDefault() thus affecting also other important things like NumberFormats. Imagine as example an application which should have English GUI texts, but should use the default locale of France (which uses f.ex. comma as decimal separator instead of decimal point) for NumberFormats.
In the meantime i changed my application so that it sets every single GUI text via code.
It took some work, but now i can change the GUI language independently from the default locale, which i can use for NumberFormats.
But if somebody has an idea how i could change the runtime language of GUI texts in IntelliJ independently from the default locale
without coding the texts (just via designer) this would be great.
thanks
Oliver
Unfortunately, there is no way to ge the (object, field, i18n-key) association you would need, at least without doing fun stuff like walking the stack or parsing java byte code (which is way too fragile for my taste). The association is private to the GUI-builder, who uses it to produce lines like
this.$$$loadLabelText$$$(label1, ResourceBundle.getBundle("resources/i18n").getString("PI_ADMIN_TITLE"));
... and unfortunately, there is no simple way of getting out the (label1, "text", "PI_ADMIN_TITLE") tuple you would need in order to help
switching language automatically.
With access to the source code to the UI-designer, it would be a trivial job.