简体   繁体   中英

Vaadin portlet dynamic language change

I have an Vaadin portlet wich supports "Multilanguage" that means if an user selects for eg DE in the liferay portal he will get the German translation of some portlets and if he select another language the portlet will be translated to the selected language. there is a problem, the user can translate the portlet only one time , if he selects another language, the portlet keeps the translated strings of the previous language , and the portlet keeps the old language till the portlets init method is reloaded. is there a way to dynamicaly change the language of the portlets components without losing the curret users state(modifications) ?

There is a pattern for Vaadin component translation that may apply here:

  1. Create a utility method to translate Vaadin Component's caption and description properties. Use ThreadLocal -pattern to make that look like a static method or use dependency injection to make it easier call it from everywhere.
  2. In the translating method store the original translation key (string id) to Component.setData()
  3. On dynamic language change call the method to re-translate the component using the Component.getData property. You can easily iterate through the whole visible UI using the ComponentContainer interface starting from the Window.

For storing multiple translation keys into data-property (for the caption and description separately) create your own class or use Map.

Note also that if you have data coming from the database, this pattern does not help and you have to solve that some other way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM