As continue to my previous blog, sometimes we get requirement to display locale message in 'Notifications' or 'Alerts'. It is easy to diplay in jsp page in labels but how to display in alerts then the below is an example which will help you on this type of requirement.
example :-
.jsp code :-
function modeAlert(){
alert("<liferay-ui:message key="payment"/>");
}
.js code :-
Liferay.Language.get('key');
--------------------------------------------------------------------------
Path for Language properties file :- src/content/Language_en_US.properties
Language_en_US.properties :- ex: (Key : Vlaue)
payment: Payment
Language_ms_MY.properties :- ex: (Key : Vlaue)
payment: Pembayaran
When ever you use the above key(first way or second way) depending upon the current locale the value will be diplayed.
WEB-INF/Portlet.xml :- The entry in the portlet.xml is also mandatory then only you can able to see the values otherwise you can see only key as output.
<portlet>
<portlet-name>request</portlet-name>
<display-name>Request</display-name>
<portlet-class>com.Request</portlet-class>
<init-param>
</init-param>
<supports>
</supports>
<supported-locale>en_US</supported-locale>
<supported-locale>ms_MY</supported-locale>
<resource-bundle>content.Language</resource-bundle>
<portlet-info>
</portlet-info>
</portlet>
example :-
.jsp code :-
function modeAlert(){
alert("<liferay-ui:message key="payment"/>");
}
.js code :-
Liferay.Language.get('key');
--------------------------------------------------------------------------
Path for Language properties file :- src/content/Language_en_US.properties
Language_en_US.properties :- ex: (Key : Vlaue)
payment: Payment
Language_ms_MY.properties :- ex: (Key : Vlaue)
payment: Pembayaran
When ever you use the above key(first way or second way) depending upon the current locale the value will be diplayed.
WEB-INF/Portlet.xml :- The entry in the portlet.xml is also mandatory then only you can able to see the values otherwise you can see only key as output.
<portlet>
<portlet-name>request</portlet-name>
<display-name>Request</display-name>
<portlet-class>com.Request</portlet-class>
<init-param>
</init-param>
<supports>
</supports>
<supported-locale>en_US</supported-locale>
<supported-locale>ms_MY</supported-locale>
<resource-bundle>content.Language</resource-bundle>
<portlet-info>
</portlet-info>
</portlet>
No comments:
Post a Comment