Localization in the portal module

I have 2 langages and 2 messages_xx_xx.properties files. How can i get a localized message from the portal module page with thymeleaf?
In the controller with

    @Inject
    private Messages messages;

I can get the localized text but how can I get one in a HTML page?

for now I get this : ??warningMessage_fr_FR?? when I use

someText


I must miss something

Thanks

Hi,

Unfortunately, it is not supported out-of-the-box.

You could enable messages.properties localization in your portal-spring-dispatcher.xml in the following way:

    <bean id="thymeleafMessageSource" class="com.company.demo.portal.sys.ThymeleafMessageSource"/>

    <bean id="thymeleafTemplateEngine"
          class="org.thymeleaf.spring4.SpringTemplateEngine">
        <property name="templateResolver" ref="thymeleafTemplateResolver"/>
        <property name="templateEngineMessageSource" ref="thymeleafMessageSource"/>
        <property name="additionalDialects">
            <set>
                <bean class="org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect"/>
            </set>
        </property>
    </bean>

    <bean id="thymeleafViewResolver" class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
        <property name="templateEngine" ref="thymeleafTemplateEngine" />
        <property name="characterEncoding" value="UTF-8"/>
    </bean>

And create ThymeleafMessageSource class:

public class ThymeleafMessageSource implements MessageSource {
    @Inject
    private Messages messages;

    @Override
    public String getMessage(String code, Object[] args, String defaultMessage, Locale locale) {
        if (args != null && args.length > 0) {
            return messages.formatMainMessage(code, args, locale);
        }

        return messages.getMainMessage(code, locale);
    }

    @Override
    public String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException {
        if (args != null && args.length > 0) {
            return messages.formatMainMessage(code, args, locale);
        }

        return messages.getMainMessage(code, locale);
    }

    @Override
    public String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException {
        throw new NoSuchMessageException("Unsupported message resolving mechanism");
    }
}

Then, you will be able to use the standard thymeleaf localization syntax:

<h1 th:text="#{page.head}"></h1>

See this repository for the complete example: https://github.com/cuba-labs/thymeleaf-l10n

We will implement this feature in the upcoming release 6.9: https://youtrack.cuba-platform.com/issue/PL-10533