Vaadin Multilanguage portlet component captions

百般思念 提交于 2019-12-11 15:15:55

问题


I'm developing portlets with Vaadin in a Liferay Portal , mostly with english component captions(names) like "Cancel" "back" "next" and so on. Now i have to make the portlets "Multilanguage ready" that means if an user has set the language of his Liferay page to english he should see my portlet captions in english , but if an user sets the language of his Liferay page to german, the portlet captions should be displayed in german.

Is there a way to check wich language the user has set as his main Language ?

an easy Example :

John is from New York his main language is english so as soon as he logins to his account the language of the Portlet component captions should be displayed in english

Heinz is from Berlin his main language is german so as soon as he logins to his account the language of the Portlet component captions should be displayed in german.


回答1:


For getting caption from your property files you can try with (assuming above class)

Button button = new Button() {
    @Override
    public void attach() {
        ResourceBundle bundle = ResourceBundle.getBundle(Translation_portletApplication.class.getName(), user.getLocale());
        setCaption(bundle.getString("first_name"));
    }
};
window.addComponent(button);

To see full context of answer refer to this so question




回答2:


You can call user.getLocale() of Liferay API.

To get the user object, check this out. More detailed information found here (could be outdated though).



来源:https://stackoverflow.com/questions/8121638/vaadin-multilanguage-portlet-component-captions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!