Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic Internationalization (I18N) - Creating a Multilingual Application

 
Kevin Dias
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for sharing but what is wrong with this tutorial?
 
Kevin Dias
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no need to restart the application or change settings.

 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Glen Divers
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic