i18n - komunikaty nie są tłumaczone

0

Witam,
Mam aplikację w Spring MVC z thymeleaf, stworzoną za pomocą Spring Boot. Komunikaty nie są tłumaczone. Na so znalazłem, że trzeba dodać: spring.messages.basename=locale/messages, ale to nie pomaga.

package com.app.config;

import com.app.services.UsLocalDateFormatter;
import org.springframework.boot.autoconfigure.web.WebMvcProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.validation.Validator;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import java.time.LocalDate;

/**
 * Created by Marcin on 01.08.2016.
 */
@Configuration
public class WebConfiguration extends WebMvcConfigurerAdapter {
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addFormatterForFieldType(LocalDate.class, new
                UsLocalDateFormatter());
    }

    @Bean
    public LocaleResolver localeResolver() {
        return new SessionLocaleResolver();
    }

    @Bean
    public LocaleChangeInterceptor localeChangeInterceptor() {
        LocaleChangeInterceptor localeChangeInterceptor = new
                LocaleChangeInterceptor();
        localeChangeInterceptor.setParamName("lang");
        return localeChangeInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(localeChangeInterceptor());
    }
}

application.properties

logging.level.org.springframework.web = DEBUG #pytanie czemu jednak komunikaty błędów mi się nie pokazują?
spring.messages.cache-seconds=0
#spring.mvc.locale=en
#messages
#messages
spring.messages.basename=locale/messages

problemi18n.PNG
i18n2.PNG

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="layout/default">
<head lang="pl">
    <title>Twój profil</title>
</head>
<body>
<div class="row" layout:fragment="content">
    <h2 class="indigo-text center" th:text="#{profile.title}">
        Informacje osobiste</h2>
    <form th:action="@{/profile}" th:object="${profileForm}" method="post"
          class="col m8 s12 offset-m2">
        <div class="row">
            <div class="input-field col s6">
                <input th:field="${profileForm.twitterHandle}" id="twitterHandle"
                       type="text" th:errorclass="invalid"/>
                <label for="twitterHandle" th:text="#{twitter.handle}">
                    Identyfikator Twitter
                </label>
                <div th:errors="*{twitterHandle}" class="redtext">Błąd</div>
            </div>
            <div class="input-field col s6">
                <input th:field="${profileForm.email}" id="email" type="text"
                       th:errorclass="invalid"/>
                <label for="email" th:text="#{email}">Adres e-mail</label>
                <div th:errors="*{email}" class="red-text">Błąd</div>
            </div>
        </div>
        <div class="row">
            <div class="input-field col s6">
                <input th:field="${profileForm.birthDate}" id="birthDate" type="text"
                       th:errorclass="invalid"/>
                <label for="birthDate" th:text="#{birthdate}"
                       th:placeholder="${dateFormat}">Data urodzenia</label>
                <div th:errors="*{birthDate}" class="red-text">Błąd</div>
            </div>
        </div>
        <div>
            <fieldset class="row">
                <legend th:text="#{tastes.legend}">Co lubisz?</legend>
                <button class="btn teal" type="submit" name="addTaste"
                        th:text="#{add.taste}">Dodaj preferencję
                    <i class="mdi-content-add left"></i>
                </button>
                <div th:errors="*{tastes}" class="red-text">Błąd</div>
                <div class="row" th:each="row,rowStat : *{tastes}">
                    <div class="col s6">
                        <input type="text" th:field="*{tastes[__${rowStat.index}__]}"
                               th:placeholder="#{taste.placeholder}"/>
                    </div>
                    <div class="col s6">
                        <button class="btn red" type="submit" name="removeTaste"
                                th:value="${rowStat.index}" th:text="#{remove}">Usuń
                            <i class="mdi-action-delete right waves-effect"></i>
                        </button>
                    </div>
                </div>
            </fieldset>
        </div>
        <div class="row s12 center">
            <button class="btn indigo waves-effect waves-light" type="submit"
                    name="save"
                    th:text="#{submit}">Wyślij
                <i class="mdi-content-send right"></i>
            </button>
        </div>
    </form>
</div>
</body>
</html>
0

Rozwiązanie: stworzyłem w resources folder locale, w nim są pliki z tłumaczeniami i dodałem poniższy kod. Teraz działa.

 
    @Bean
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setBasename("classpath:/locale/messages");
        messageSource.setDefaultEncoding("UTF-8");
        return messageSource;
    }

1 użytkowników online, w tym zalogowanych: 0, gości: 1