简体   繁体   English

Vaadin Portlet动态语言更改

[英]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. 我有一个支持“多语言”的Vaadin portlet,这意味着,如果用户在liferay门户中选择DE,例如,他将获得某些portlet的德语翻译,如果他选择另一种语言,则该portlet将被翻译为所选语言。 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. 有一个问题,用户只能翻译一次portlet,如果他选择另一种语言,则portlet保留先前语言的翻译后的字符串,而portlet保留旧的语言,直到重新加载portlet的init方法为止。 is there a way to dynamicaly change the language of the portlets components without losing the curret users state(modifications) ? 有没有一种方法可以动态地更改portlet组件的语言而又不会丢失当前用户的状态(修改)?

There is a pattern for Vaadin component translation that may apply here: Vaadin组件翻译的模式可能适用于此处:

  1. Create a utility method to translate Vaadin Component's caption and description properties. 创建一个实用程序方法来转换Vaadin组件的标题和描述属性。 Use ThreadLocal -pattern to make that look like a static method or use dependency injection to make it easier call it from everywhere. 使用ThreadLocal -pattern使它看起来像一个静态方法,或使用依赖项注入使其更容易从任何地方调用它。
  2. In the translating method store the original translation key (string id) to Component.setData() 在翻译方法中,将原始翻译键(字符串ID)存储到Component.setData()
  3. On dynamic language change call the method to re-translate the component using the Component.getData property. 在进行动态语言更改时,调用方法以使用Component.getData属性重新转换组件。 You can easily iterate through the whole visible UI using the ComponentContainer interface starting from the Window. 您可以使用从Window开始的ComponentContainer接口轻松地遍历整个可见的UI。

For storing multiple translation keys into data-property (for the caption and description separately) create your own class or use Map. 要将多个转换键存储到数据属性中(分别用于标题和描述),请创建您自己的类或使用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. 还要注意,如果您有来自数据库的数据,则此模式无济于事,您必须以其他方式解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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