Im am using Vaadin 7.1 and need to be able to change the form / screen / UI Locale dynamically (user can select the preferred form locale). By changing the form locale i mean changing field names / captions, window title, user messages / notification, and so on.
This is not trivial with Vaadin afaik. What is the best practice for this use case? Any advice for external libraries / design approach will be highly appreciated!
you’re correct - it’s not that easy to do it on the fly. The usual (easiest/quickest/cheapest) approach for changing the locale is to allow the user to either select it on login and apply it starting from there, or allow the user to set the locale in some user settings view and then it will be applied after a relogin.
I achieved this with storing the Locale the user selected in the User-Session and wrapped methods which set e.g. captions to use the locale in the session to display the right language.
@Teppo. I have looked at the i18n4vaadin add-on, but “on the fly updating the components” (what I want to achieve) is
not supported: “you have to remember to update all your UI components since this is not something I18N4Vaadin can do automatically.” Secondly, it does not fit well in our application architecture (we use declarative/XML based layouts).
@Holger. Our approach we are now trying (not finalized): Get a reference to the current UI, walk the component tree and update all String setters with an i18n key by using reflection.
This is maybe not what you’d like to hear, but think if it actually is worth implementing. It usually is a lot of work and error prone to try to traverse every component in the whole application. What I usually do is either force a refresh out of the application, or have a separate initialization method in UI which I can call to reinitialize the whole UI. This combined with navigator gets me into the right view with updated captions.
It’s a trade-off between usability and effort. In my opinion the required effort is quite big while the hit on usuability is quite low, and thus I’ve come to the conclusion that reinitializing the UI gives me the most value out of the effort.