Fórum

Portlet custom Title

sunil kumar, modificado 6 Anos atrás.

Portlet custom Title

New Member Postagens: 13 Data de Entrada: 28/03/17 Postagens Recentes
Hi, I want to show portlet custom title specific to selected language, but this it working only for single language(JAPANESE).
Portlet are added at run time.
I dont want to use portlet.xml because number of portlet are created at run time & are much in number.


Code:
# many portlets are created in loop
<liferay-ui:section>
<liferay-portlet:runtime portletName='<%= pName %>' queryString="" defaultPreferences="<%= defaultPreferences %>" />
</liferay-ui:section>
# loop end

& data in default preference is :
String defaultPreferences = "";
StringBuilder sb = new StringBuilder();

sb.append("<portlet-preferences>");
sb.append("<preference>");
sb.append("<name>");
sb.append("portletSetupUseCustomTitle");
sb.append("</name>");
sb.append("<value>");
sb.append("true");
sb.append("</value>");
sb.append("</preference>");

if (locale.toString().equals("en_US")) {
sb.append("<preference>");
sb.append("<name>");
sb.append("portletSetupTitle_en_US");
sb.append("</name>");
sb.append("<value>");
sb.append("ENGLISH_TITLE");
sb.append("</value>");
sb.append("</preference>");
}


if (locale.toString().equals("ja_JP")) {
sb.append("<preference>");
sb.append("<name>");
sb.append("portletSetupTitle_ja_JP");
sb.append("</name>");
sb.append("<value>");
sb.append("JAPANESE TITLE");
sb.append("</value>");
sb.append("</preference>");
}
sb.append("</portlet-preferences>");
defaultPreferences = sb.toString();

please see attached images for reference.
Thnanks
Suneel
thumbnail
Andrew Jardine, modificado 6 Anos atrás.

RE: Portlet custom Title

Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
Hi Sunil,

I'm not exactly clear on what you are doing perhaps, but that looks like the wrong solution to me. Let's say I have portlet A, that is embedded on say, the homepage. The portlet A itself in terms of functionality I assume will be the same whether the title is in Japanese, or English or Russian or Spanish, etc. You just want to set the title dynamically? -- I am assuming that your portlet also has labels on buttons, text, headings etc that is being translated to each of the supported languages as well right? In which case you must have a language bundle specified for your portlet in you portlet (portlet.xml, or annotations in LR7). Inside the bundle you can use

javax.portlet.title=<title based on language>&lt;/code&gt;&lt;/pre&gt;</title><br><br>-- if this is a 6.2 or earlier project and you have more than one portlet defined inside the portlet.xml, just make sure to give them each unique properties file names as part of the resource-bundle definition and you can use the same format. So rather than use Language.properties or Portlet A and Portlet B ... use PortletA_Language.properties and PorltetB_Language.properties -- where each file will have the javax.portlet.title defined.<br><br>This is all assuming I have not completely misunderstood your question.