I need to check in my portlet wich language does an user have selected as his "main" language, to do that, I have to get the UserID (name) first . i have been looking for it for two days (Liferay forums , vaadin forums , stackoverflow etc.) but nothing found that would work so far.
I have found an nice example but it doesnt seem to work (It always returns "null").
package com.example.translation_portlet;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.User;
import com.liferay.portal.util.PortalUtil;
import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.PortletRequestListener;
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;
public class Translation_portletApplication extends Application implements
PortletRequestListener {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void init() {
Window mainWindow = new Window("LoginApplication");
Label label = new Label("Hello anonymous Vaadin user");
if (getUser() != null) {
// user has logged in
label = new Label("Hello " + ((User) getUser()).getFullName());
}
mainWindow.addComponent(label);
setMainWindow(mainWindow);
}
@Override
public void onRequestStart(PortletRequest request, PortletResponse response) {
if (getUser() == null) {
try {
User user = PortalUtil.getUser(request);
setUser(user);
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
}
}
@Override
public void onRequestEnd(PortletRequest request, PortletResponse response) {
// Nothing to do here currently, exists only to implement the
// PortletRequestListener interface.
}
}
EDIT :
this is what i have tryed so far :
locale = user.getLocale();
button.setCaption(LanguageUtil.get(locale, "first_name"));
and in my Language.properties i have the translation for "first_name" set to 1st Name:
first_name=1st Name
the Language.properties file is located in my content folder i have added and resource-bundle to my portlet.xml too :
<resource-bundle>content/Language</resource-bundle>
The caption of the button is set to "first_name" not 1st name , if i change the key to first-name i get an default translation no my tranlsation from the language.properties file , am i missing something ?