title: Spring Boot & Thymeleaf - Localized text does not appear
body: <p>I am currently working on the localization of my (second) Spring Boot project. However, I have come to a halt after several hours of struggling: I am unable to get a user-editable Session localization.</p>
  <p>The problem appears to occur as soon as the user sends a GET request with the lang parameter. <em>(travel down below to see the results I am getting)</em></p>
  <h1>Details</h1>
  <p><em>Spring Boot version:(3.0.0-M3)</em></p>
  <h2>Expected localized content</h2>
  <p><em>i18n/messages.properties is <strong>empty</strong></em></p>
  <p><strong>i18n/messages_en_US.properties:</strong></p>
  <pre><code>morning=good morning
  afternoon=bye
  </code></pre>
  <p><strong>i18n/messages_fr_FR.properties:</strong></p>
  <pre><code>morning=salut
  afternoon=a+
  </code></pre>
  <p><strong>i18n/messages_ja_JP.properties:</strong></p>
  <pre><code>morning=ohayou
  afternoon=jane
  </code></pre>
  <h2>Configuration</h2>
  <p><strong>application.properties</strong> (section related to this issue):</p>
  <pre><code>spring.messages.always-use-message-format=true
  spring.messages.basename=i18n.messages
  spring.messages.fallback-to-system-locale=false
  spring.messages.use-code-as-default-message=false
  </code></pre>
  <p><strong>LocalizationConfiguration file:</strong></p>
  <pre class="lang-java prettyprint-override"><code>import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.servlet.LocaleResolver;
  import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
  import org.springframework.web.servlet.i18n.SessionLocaleResolver;
  
  @Configuration
  public class LocalizationConfiguration implements WebMvcConfigurer {
  
      @Bean
      public LocaleResolver localeResolver() {
          SessionLocaleResolver localeResolver = new SessionLocaleResolver();
          // localeResolver.setDefaultLocale(Locale.US);
          return localeResolver;
      }
  
      @Bean
      public LocaleChangeInterceptor localeChangeInterceptor() {
          LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
          localeChangeInterceptor.setParamName(&quot;lang&quot;);
          return localeChangeInterceptor;
      }
  
      @Override
      public void addInterceptors(InterceptorRegistry interceptorRegistry) {
          interceptorRegistry.addInterceptor(localeChangeInterceptor());
      }
  
  }
  </code></pre>
  <h2>Display</h2>
  <p><strong>Page Controller:</strong></p>
  <pre class="lang-java prettyprint-override"><code>@GetMapping
  @RequestMapping(value = &quot;/international&quot;)
  public String getInternationalView(Model model) {
      return &quot;international&quot;;
  }
  </code></pre>
  <p><strong>Template loaded</strong> (international.html):</p>
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns:th=&quot;https://www.thymeleaf.org&quot; th:with=&quot;lang=${#locale.language}&quot; th:lang=&quot;${lang}&quot;&gt;
  &lt;head&gt;
  &lt;script src=&quot;https://kit.fontawesome.com/2f4c03ee9b.js&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
  
  &lt;script th:src=&quot;@{/webjars/jquery/3.0.0/jquery.min.js}&quot;&gt;&lt;/script&gt;
  &lt;script th:src=&quot;@{/webjars/popper.js/2.9.3/umd/popper.min.js}&quot;&gt;&lt;/script&gt;
  &lt;script th:src=&quot;@{/webjars/bootstrap/5.1.3/js/bootstrap.min.js}&quot;&gt;&lt;/script&gt;
  &lt;link th:rel=&quot;stylesheet&quot; th:href=&quot;@{/webjars/bootstrap/5.1.3/css/bootstrap.min.css} &quot;/&gt;
  
  &lt;meta charset=&quot;UTF-8&quot;/&gt;
  &lt;title&gt;Localization tests&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;p th:text=&quot;${#locale}&quot;&gt;&lt;/p&gt;
      &lt;p th:text=&quot;#{morning}&quot;&gt;&lt;/p&gt;
      &lt;p th:text=&quot;#{afternoon}&quot;&gt;&lt;/p&gt;
      
      &lt;div class=&quot;dropdown&quot;&gt;
          &lt;button class=&quot;btn btn-primary dropdown-toggle&quot; type=&quot;button&quot; id=&quot;dropdownMenuButton1&quot; data-bs-toggle=&quot;dropdown&quot; aria-expanded=&quot;false&quot;&gt;
              &lt;i class=&quot;fa-solid fa-language fa-4x&quot;&gt;&lt;/i&gt;
          &lt;/button&gt;
          &lt;ul class=&quot;dropdown-menu&quot; aria-labelledby=&quot;dropdownMenuButton1&quot;&gt;
              &lt;li&gt;&lt;a class=&quot;dropdown-item&quot; th:href=&quot;@{''(lang=en)}&quot;&gt;English&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a class=&quot;dropdown-item&quot; th:href=&quot;@{''(lang=fr)}&quot;&gt;Français&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a class=&quot;dropdown-item&quot; th:href=&quot;@{''(lang=jp)}&quot;&gt;日本語&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <h1>What is being displayed</h1>
  <p><a href="https://i.stack.imgur.com/7qtb2.gif" rel="nofollow noreferrer">Found result</a></p>
  <p>As you can see in the above gif, the first display of the page shows the messages in the browser's language. However, as soon as an other language is selected the page breaks apart, with the exception of the <strong>#locale</strong> parameter.</p>