Forums de discussion
Internationalization in javaScript of sepearate Portlet War file
c c c, modifié il y a 15 années.
Internationalization in javaScript of sepearate Portlet War file
Junior Member Publications: 42 Date d'inscription: 08/11/07 Publications récentes
We have created a portlet and deployed in Liferay and provided it custom Resource properties as
<resource-bundle>Resource</resource-bundle>
We have used the following code for getting the contents through JavaScript
alert(Liferay.Language.get("AHellotest"));
but it gets me AHellotest itself instead of "Hello Test" which is mentioned in Resource.properties
Normal <liferay-ui:message key="AHellotest" /> works properly
Thanks in advance
CSJakharia
<resource-bundle>Resource</resource-bundle>
We have used the following code for getting the contents through JavaScript
alert(Liferay.Language.get("AHellotest"));
but it gets me AHellotest itself instead of "Hello Test" which is mentioned in Resource.properties
Normal <liferay-ui:message key="AHellotest" /> works properly
Thanks in advance
CSJakharia
Ray Augé, modifié il y a 15 années.
Re: [Liferay Forums][3. Development] Internationalization in javaScript of
Liferay Legend Publications: 1197 Date d'inscription: 08/02/05 Publications récentes
> alert(Liferay.Language.get("AHellotest"));
>
> but it gets me AHellotest itself instead of "Hello Test" which is
> mentioned in Resource.properties
>
> Normal <liferay-ui:message key="AHellotest" /> works properly
It's because there is no way for the Language servlet (which is called
by Liferay.Language) to know about the portlet context.
Therefore it would be better to load all your translations into an
object if you plan on doing heavy js manipulation of the view.
e.g.
Now in your js you can simply refer to each key through
the <portlet:namespace />lang object.
PS: I'm know there are web frameworks that handle js/portlet
localization, but this is a most basic approach.
>
> but it gets me AHellotest itself instead of "Hello Test" which is
> mentioned in Resource.properties
>
> Normal <liferay-ui:message key="AHellotest" /> works properly
It's because there is no way for the Language servlet (which is called
by Liferay.Language) to know about the portlet context.
Therefore it would be better to load all your translations into an
object if you plan on doing heavy js manipulation of the view.
e.g.
<%@ page import="com.liferay.portal.kernel.language.LanguageUtil" %>
<%@ page import="com.liferay.portal.kernel.util.UnicodeFormatter" %>
<%
String[] myLangKeys = new String[]{
"AHelloTest",
...
};
StringBuilder sb = new StringBuilder();
sb.append("var MyLang = {\n");
for (String key : myLangKeys) {
sb.append(" ");
sb.append(key);
sb.append(":'");
sb.append(UnicodeFormatter.toString(LanguageUtil.get(pageContext, key)));
sb.append("',\n");
}
sb.append(" null:''\n");
sb.append("};\n");
%>
<script tyle="text/javascript">
<%= sb.toString() %>
</script>
Now in your js you can simply refer to each key through
the <portlet:namespace />lang object.
alert(MyLang.AHellotest);
PS: I'm know there are web frameworks that handle js/portlet
localization, but this is a most basic approach.
Jakub Liska, modifié il y a 13 années.
RE: Re: [Liferay Forums][3. Development] Internationalization in javaScript
Regular Member Publications: 187 Date d'inscription: 25/03/10 Publications récentes
Hi Ray,
is it still not possible to use Liferay.Language.get( ) on portlet context ? Or it is now.
Because if you look at mail-portlet/docroot/js/main.js , it is used there
. I don't know why it works there, but regarding my portlet, LanguageServlet is never called
Thank you
btw: is there something like Alloy API for the rest of Javascript libs ? Or I should browse the source code.
is it still not possible to use Liferay.Language.get( ) on portlet context ? Or it is now.
Because if you look at mail-portlet/docroot/js/main.js , it is used there
. I don't know why it works there, but regarding my portlet, LanguageServlet is never called
Thank you
btw: is there something like Alloy API for the rest of Javascript libs ? Or I should browse the source code.