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:
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.
Joined: Nov 04, 2009
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.
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.
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?
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.