Forums

angle-left Back

i18n support in JSF Liferay 7

KB
Karel Bělunek, modified 11 Months ago.

i18n support in JSF Liferay 7

New Member Posts: 8 Join Date: 6/23/17 Recent Posts
I have fond a problem with internationalisation in Liferay Faces in Liferay 7 ga4

I did not found any Liferay 7 related i18n documentation and when I followed 6.2 documentation (https://dev.liferay.com/develop/tutorials/-/knowledge_base/6-2/localizing-jsf-portlets) - it behaves strange.

I attached simple example - Primefaces module by liferayfaces.org maven generetor and I added locale-config into faces-config.xml.

The result is, that JSF portlet ignores language setting set by Liferay language selector and uses one of alternative langueges (czech).
Also the czech message ifs malformed, it looks that the portlet does not use UTF-8 form displaying characters with accents.

Souce code anf few screensthots are attached.

What is the correct way to use liferay intenationalization is JSF environment?

Regards

Karel B.
Neil Griffin, modified 11 Months ago.

RE: i18n support in JSF Liferay 7 (Answer)

LIFERAY STAFF Liferay Legend Posts: 2540 Join Date: 7/26/05 Recent Posts
Hi Karel,

Thanks for posting your question and for providing a good reproducer portlet. You might be encountering FACES-2996. Please try our latest SNAPSHOT dependencies and see if the problem goes away:
<repositories>
    <repository>
        <id>liferay-faces-snapshots</id>
        <name>Liferay Faces Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.liferay.faces</groupId>
        <artifactId>com.liferay.faces.bridge.ext</artifactId>
        <version>5.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.liferay.faces</groupId>
        <artifactId>com.liferay.faces.bridge.impl</artifactId>
        <version>4.1.0-SNAPSHOT</version>
        <!-- NOTE: This has a transitive dependency on com.liferay.faces.bridge.api-4.1.0-SNAPSHOT.jar -->
    </dependency>
    <dependency>
        <groupId>com.liferay.faces</groupId>
        <artifactId>com.liferay.faces.util</artifactId>
        <version>3.1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.liferay.faces</groupId>
        <artifactId>com.liferay.faces.portal</artifactId>
        <version>3.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>


Kind Regards,

Neil
KB
Karel Bělunek, modified 11 Months ago.

RE: i18n support in JSF Liferay 7

New Member Posts: 8 Join Date: 6/23/17 Recent Posts
Hi Neil,

the snapshot version works corectly, thank you very much!

Please, what is the current roadmap for release of the fixed version?

An I have, please, additional question.
Standard way how to access ResourceBundle from JSF backing bean is:

@ManagedProperty("#{i18n}")
private ResourceBundle text;


This approach does not work because injected object is of type com.liferay.faces.util.el.internal.I18nMap, so I changed definition to
@ManagedProperty("#{i18n}")
private I18nMap text;


an I am accessing keys using: text.get("com.mycompany.my.primefaces.portlet-hello-world").toString();

Everything works but the I18nMap object belongs to package com.liferay.faces.util.el.internal - this "internal" worries me.

Is my approach for loading keys correct? I am trying to prevent usage of some internal stuff that is not intended to be used as an API.

Kind regards

Karel B.
Neil Griffin, modified 11 Months ago.

RE: i18n support in JSF Liferay 7 (Answer)

LIFERAY STAFF Liferay Legend Posts: 2540 Join Date: 7/26/05 Recent Posts
Hi Karel,

I'm glad that the snapshot versions are working well for you. The Liferay Faces team is currently in a bugfix sprint working towards our next release, which is planned for August.

Regarding i18n, it is good that the sub-package "internal" became a cause for your concern. Everything under "internal" sub-packages is not API (an implementation detail) and subject to change at any time.

For the injection type, you can use Map<String, Object> instead of the internal implementation type. Alternatively you could access the I18n factory:

FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
I18n i18n = I18nFactory.getI18nInstance(externalContext);



Kind Regards,

Neil
KB
Karel Bělunek, modified 11 Months ago.

RE: i18n support in JSF Liferay 7

New Member Posts: 8 Join Date: 6/23/17 Recent Posts
Hi Neil,

The Map<String,Object> injection works correctly.

Thank you for the advice.

Kind regards

Karel B.
Neil Griffin, modified 11 Months ago.

RE: i18n support in JSF Liferay 7

LIFERAY STAFF Liferay Legend Posts: 2540 Join Date: 7/26/05 Recent Posts
Hi Karel,

I'm glad to know that it is working for you now, and thanks for using Liferay Faces! emoticon

Kind Regards,

Neil