Changing Locale setting at runtime

Discussion in 'Java' started by napo, Jul 10, 2007.

  1. napo

    napo Guest

    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, Jul 10, 2007
    #1
    1. Advertising

  2. napo

    napo Guest

    Nobody knows?

    Hi
    Marco
     
    napo, Jul 15, 2007
    #2
    1. Advertising

  3. napo

    Tom Hawtin Guest

    napo wrote:
    > 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
     
    Tom Hawtin, Jul 15, 2007
    #3
  4. napo

    napo Guest

    > 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
     
    napo, Jul 15, 2007
    #4
  5. napo

    Roedy Green Guest

    On Tue, 10 Jul 2007 17:19:20 +0200, "napo" <>
    wrote, quoted or indirectly quoted someone who said :

    > 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
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Jul 15, 2007
    #5
  6. napo

    napo Guest

    > 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
     
    napo, Jul 15, 2007
    #6
  7. napo

    Roedy Green Guest

    On Mon, 16 Jul 2007 00:01:13 +0200, "napo" <>
    wrote, quoted or indirectly quoted someone who said :

    >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.


    see http://mindprod.com/jgloss/locale.html
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Jul 15, 2007
    #7
  8. napo

    Real Gagnon Guest

    Real Gagnon, Jul 16, 2007
    #8
  9. napo

    Twisted Guest

    On Jul 15, 5:49 pm, Roedy Green <>
    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.
     
    Twisted, Jul 16, 2007
    #9
  10. napo

    Roedy Green Guest

    On Mon, 16 Jul 2007 13:13:12 -0000, Twisted <>
    wrote, quoted or indirectly quoted someone who said :

    >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.

    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Jul 16, 2007
    #10
  11. napo

    Roedy Green Guest

    On Mon, 16 Jul 2007 13:13:12 -0000, Twisted <>
    wrote, quoted or indirectly quoted someone who said :

    >
    >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
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Jul 16, 2007
    #11
  12. napo

    Twisted Guest

    On Jul 16, 4:04 pm, Roedy Green <>
    wrote:
    > On Mon, 16 Jul 2007 13:13:12 -0000, Twisted <>
    > wrote, quoted or indirectly quoted someone who said :
    >
    > >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.
     
    Twisted, Jul 17, 2007
    #12
  13. napo

    chaitanyat2001

    Joined:
    Sep 23, 2008
    Messages:
    2
    Similar problem, plz help

    Hey Marco,
    I am also working on RCP apps & now facing same requirement you faced. So if you can provide info. how you solved that or any info. on that how to approach or any alternative, that would be great. Thanks in advance & expecting a reply from your side.

    regards
    Chats
     
    chaitanyat2001, Sep 23, 2008
    #13
  14. napo

    chaitanyat2001

    Joined:
    Sep 23, 2008
    Messages:
    2
    Hey Marco,
    I am also working on RCP apps & now facing same requirement you faced. So if you can provide info. how you solved that or any info. on that how to approach or any alternative, that would be great. Thanks in advance & expecting a reply from your side.

    regards
    Chats
     
    chaitanyat2001, Sep 23, 2008
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Polite
    Replies:
    1
    Views:
    1,440
    Alan Moore
    Jun 5, 2004
  2. Torsten Bronger

    Setting locale at runtime

    Torsten Bronger, Apr 11, 2005, in forum: C Programming
    Replies:
    3
    Views:
    434
    Peter Nilsson
    Apr 12, 2005
  3. Replies:
    4
    Views:
    1,053
  4. Sibylle Koczian
    Replies:
    2
    Views:
    1,162
    Sibylle Koczian
    Nov 20, 2010
  5. Vlastimil Brom
    Replies:
    0
    Views:
    989
    Vlastimil Brom
    Dec 9, 2010
Loading...

Share This Page