File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Dynamic Internationalization (I18N) - Creating a Multilingual Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Dynamic Internationalization (I18N) - Creating a Multilingual Application" Watch "Dynamic Internationalization (I18N) - Creating a Multilingual Application" New topic
Author

Dynamic Internationalization (I18N) - Creating a Multilingual Application

Kevin Dias
Greenhorn

Joined: Nov 04, 2009
Posts: 5
When I was developing an application that needed to be dynamically internationalized (allow the user to change the language while the program is running), I was having a hard time finding some example code. Therefore, I decided to write up an example. Hopefully this can be helpful to someone in the future:

Dynamic Internationalization Example

Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Thank you for sharing but what is wrong with this tutorial?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Kevin Dias
Greenhorn

Joined: Nov 04, 2009
Posts: 5
There is nothing wrong with that tutorial. However, that tutorial demonstrates static internationalization. If you want the application to run on a different locale you would need to restart the application, or change the settings on your OS. I wanted to create a tutorial that went over dynamic internationalization, being able to change the locale "on-the-fly" while the program is running.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

There is no need to restart the application or change settings.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Well, if the user interface only sets the captions at create time then the new messages are not propagated. You should refresh the user interface by adding calls to "label.setText(...);" etc. For larger user interface entities (like frames, panels) you could add methods to update them in bulk.

Moving to Swing.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Glen Divers
Ranch Hand

Joined: Jan 21, 2010
Posts: 61
How do you handle other issues, such as layout with dynamic I18N, for example, a button label, or a text label being significantly longer or shorter than the original design language. Could you switch from a left->right to a right->left locale?

Regards
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Gilbert Ostlethwaite wrote:How do you handle other issues, such as layout with dynamic I18N, for example, a button label, or a text label being significantly longer or shorter than the original design language.

If your layout managers use the preferred size of all components then all you need to do is call pack() on your windows again.

Could you switch from a left->right to a right->left locale?

If you have not hard coded locations inside your user interface (as in "this label goes on the left, this button goes on the right") but leave it to the layout manager then it should use that. FlowLayout and GridLayout for instance use the component orientation of the containers it is used for. That said, you would probably need to update the component orientation as well when you change the labels.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic Internationalization (I18N) - Creating a Multilingual Application