Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

Changing Locale setting at runtime

Thread view: 
napo - 10 Jul 2007 16:19 GMT
Hi,
I'm developing an RCP application based on Eclipse 3.3.
I wrote it down in my language and then I translated it using Externalize
mechanism in Eclipse.
When the application starts, a little login form appears. On that form
there's a combobox with a list of languages.
When I select a language I need to have the form (and the application)
translated on-the-fly, without restart or something else.
In the selection event of the combobox I wrote down:
   Locale.setDefault(localeSelectedFromCombo);
but I want the application to be translated at runtime.

How can I do that?

Hi
Marco
napo - 15 Jul 2007 18:12 GMT
Nobody knows?

Hi
Marco
Tom Hawtin - 15 Jul 2007 18:48 GMT
> Nobody knows?

I can't find your original post.

Anyway, assuming you want to set the default locale in a running Java
program:

If you do not have a security manager, you can use Locale.setDefault.
Obviously you wouldn't want, say, an applet to change the locale setting
for the whole JVM. It also wont update any cases where the default
locale has already been read.

A better way to do it is to read the default locale only once. As you
construct locale-sensitive objects, pass them an object that wraps
locale and allows callbacks (listeners) to be registered for changes.

Tom Hawtin
napo - 15 Jul 2007 19:35 GMT
> I can't find your original post.

That's the original post.

I'm developing an RCP application based on Eclipse 3.3.
I wrote it down in my language and then I translated it using Externalize
mechanism in Eclipse.
When the application starts, a little login form appears. On that form
there's a combobox with a list of languages.
When I select a language I need to have the form (and the application)
translated on-the-fly, without restart or something else.
In the selection event of the combobox I wrote down:
   Locale.setDefault(localeSelectedFromCombo);
but I want the application to be translated at runtime.

Hi
Marco
Roedy Green - 15 Jul 2007 22:49 GMT
>    Locale.setDefault(localeSelectedFromCombo);
>but I want the application to be translated at runtime.

You can set the system property that controls the locale on the
command line.  See http://mindprod.com/jgloss/properties.html for
details

I have never tried it, but you could try setting the system
properties.

In a pinch you would programmatically exec another JVM with the
modified locale.
see http://mindprod.com/jgloss/exec.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

napo - 15 Jul 2007 23:01 GMT
> You can set the system property that controls the locale on the
> command line.  See http://mindprod.com/jgloss/properties.html for
> details

Mine is not a problem of configuration, I know how to change the locale.
The problem is about changing at runtime.
I made an example...
I have the login form on screen, and it's in english.
From the language combo box I choose Italian (or French, German, ...) and I
want the form to translate immediately.
I have already all the properties files with translations.

Hi
Marco
Roedy Green - 15 Jul 2007 23:40 GMT
>Mine is not a problem of configuration, I know how to change the locale.
>The problem is about changing at runtime.
[quoted text clipped - 3 lines]
>want the form to translate immediately.
>I have already all the properties files with translations.

see http://mindprod.com/jgloss/locale.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Real Gagnon - 16 Jul 2007 03:00 GMT
> I have the login form on screen, and it's in english.
> From the language combo box I choose Italian (or French, German, ...)
> and I want the form to translate immediately.
> I have already all the properties files with translations.

See the example at
http://www.rgagnon.com/javadetails/java-0135.html

Bye.
Signature

Real Gagnon  from  Quebec, Canada
* Java, Javascript, VBScript and PowerBuilder code snippets
* http://www.rgagnon.com/howto.html
* http://www.rgagnon.com/bigindex.html

Twisted - 16 Jul 2007 14:13 GMT
On Jul 15, 5:49 pm, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> In a pinch you would programmatically exec another JVM with the
> modified locale.

Are you mad?! One 260MB javaw.exe process is memory hog enough. Two at
the same time is going to be problematical on 1GB machines and
downright catastrophic on 512MB ones, where there'll be hours of
thrashing while the first one bootstraps the second one and both are
trying to be active simultaneously. Once the bootstrapper exits sanity
returns, but ... nobody likes an application that takes 72 seconds of
heavy disk activity to look like it's sorta beginning to maybe load,
and another 300 or so to actually load. :P

If you must programmatically exec the JVM with your main application
with a UI-determined locale from a bootstrapper, for Christ's sake
code the bootstrapper in C! It'll be all of 30KB that way, or around
1/1000 the size.

Java simply doesn't scale well to program sizes smaller than major
applications, when a normal (rather than micro edition) JRE is used.
Roedy Green - 16 Jul 2007 21:04 GMT
>Are you mad?! One 260MB javaw.exe process is memory hog enough

I was presuming the spawner would exit, like a salmon dying after
laying eggs.  Even if that is not possible without killing the child,
the spawner would page out of ram fairly quickly.  Further much of
javaw is now a shared DLL.

Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Twisted - 17 Jul 2007 07:42 GMT
On Jul 16, 4:04 pm, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:

> >Are you mad?! One 260MB javaw.exe process is memory hog enough
>
> I was presuming the spawner would exit, like a salmon dying after
> laying eggs.

They still run simultaneously for a while, with neither of them idle
during part of that time.

> Even if that is not possible without killing the child, the spawner would page out of ram fairly quickly.

Once it goes idle.

> Further much of javaw is now a shared DLL.

Yep - all 132KB or so of it. The 259.8 or so remaining MB of process
size being the big Java heap a separate one of which is created for
each separate running virtual machine, as near as I can figure.
Roedy Green - 16 Jul 2007 21:05 GMT
>If you must programmatically exec the JVM with your main application
>with a UI-determined locale from a bootstrapper, for Christ's sake
>code the bootstrapper in C! It'll be all of 30KB that way, or around
>1/1000 the size.

see http://mindprod.com/project/kicker.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.