1

In Spring Boot 2.6.0 java 8 application configuration class has content:


@Configuration
public class Internationalization implements WebMvcConfigurer {
 // localeResolver, localeChangeInterceptor, addInterceptors
 @Bean
 public ResourceBundleMessageSource messageSource() {
 ResourceBundleMessageSource messageSource
 = new ResourceBundleMessageSource();
 messageSource.setBasename("lang/messages");
 messageSource.setDefaultEncoding("ISO-8859-2");
 return messageSource;
 }
}

messages_pl.properties content

lang.change=Zmiana języka
switch.en=Przełącz na angielski
switch.pl=Przełącz na polski
pick.date=Wybierz rok i miesiąc
main.header=Nagłówek głównej strony

on the web page with ?lang=pl parameter and <meta charset="ISO-8859-2"> is presented with thymeleaf :

Nag?ówek g?ównej strony

Wybierz rok i miesi?c

Zmiana j?zyka: Prze??cz na angielski Prze??cz na polski

enter image description here

change to UTF-8 change doesn't help

Nag?�wek g?�wnej strony

Wybierz rok i miesi?c

Zmiana j?zyka: Prze??cz na angielski Prze??cz na polski

asked Nov 22 at 16:38
6
  • Nag?ówek g?ównej strony looks more like a font problem. Have you got a font installed to show the required glyphs? Commented Nov 22 at 16:46
  • I have not any font installed in Spring Boot java application. Html body has font-family: Tahoma, Verdana, sans-serif; Commented Nov 22 at 16:51
  • All set to UTF-8 and added Polish Font: Lato to css acc. to: stackoverflow.com/questions/73161327/… , but still no Polish characters on the page. Commented Nov 22 at 18:05
  • Are you using the same browser to view your own code output as the one you're viewing this question with? If yes, how does your posting of messages_pl.properties look? Commented Nov 22 at 18:37
  • I've tested by Chrome and Firefox, as well. Build is performed by InteliJ. Commented Nov 22 at 21:51

1 Answer 1

1
spring.messages.basename=lang/messages
spring.messages.encoding=UTF-8
spring.mvc.locale-resolver=accept-header

try adding these, let spring boot handle the configuration automatically

also, i suggest to prevent using iso encoding since most browser doesnt support or kind of overrides this. Going with UTF-8 is much better as it does what ISO does (correct me if im wrong)

answered Nov 22 at 17:09
New contributor
I Am Staple is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Sign up to request clarification or add additional context in comments.

4 Comments

maybe web.locale-resolver: accept_header ?
this could do, it will automatically modifies the language or any headers based on the client's preferences. docs.spring.io/spring-framework/reference/web/webmvc/… but downside of this is, you cant change the language through url, that's if you have a setting where users can change language or any preferences on your system. But with that property, it's automatic which is good too
still no Polish characters :(
i see can you look at your current browser settings, may it be on your browser or operating system if your preferred language is polish? because this setting depends on the user's preferred language setting

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.