From af110658b6d12b4306c383f5c1e36fd36d785d61 Mon Sep 17 00:00:00 2001 From: Alexey Zinchenko Date: Wed, 15 May 2019 22:52:33 +0300 Subject: [PATCH] Implemented locale changing. --- .../conf/ApplicationConfiguration.java | 28 +++++++++++++++++- src/main/resources/messages.properties | 4 +++ src/main/resources/messages_en.properties | 4 +++ src/main/resources/messages_ru.properties | 4 +++ src/main/resources/static/images/ru.png | Bin 0 -> 420 bytes src/main/resources/static/images/us.png | Bin 0 -> 609 bytes src/main/resources/templates/index.html | 4 +-- src/main/resources/templates/main.html | 8 +++++ src/main/resources/templates/order/index.html | 2 +- 9 files changed, 50 insertions(+), 4 deletions(-) create mode 100755 src/main/resources/static/images/ru.png create mode 100755 src/main/resources/static/images/us.png diff --git a/src/main/java/com/github/prominence/carrepair/conf/ApplicationConfiguration.java b/src/main/java/com/github/prominence/carrepair/conf/ApplicationConfiguration.java index 8f1e90c..03c683e 100644 --- a/src/main/java/com/github/prominence/carrepair/conf/ApplicationConfiguration.java +++ b/src/main/java/com/github/prominence/carrepair/conf/ApplicationConfiguration.java @@ -3,12 +3,38 @@ package com.github.prominence.carrepair.conf; import nz.net.ultraq.thymeleaf.LayoutDialect; 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; + +import java.util.Locale; @Configuration -public class ApplicationConfiguration { +public class ApplicationConfiguration implements WebMvcConfigurer { @Bean public LayoutDialect layoutDialect() { return new LayoutDialect(); } + + @Bean + public LocaleResolver localeResolver() { + SessionLocaleResolver slr = new SessionLocaleResolver(); + slr.setDefaultLocale(Locale.US); + return slr; + } + + @Bean + public LocaleChangeInterceptor localeChangeInterceptor() { + LocaleChangeInterceptor lci = new LocaleChangeInterceptor(); + lci.setParamName("lang"); + return lci; + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(localeChangeInterceptor()); + } } diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 1f94d21..f17ad71 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -5,11 +5,15 @@ badge.mechanics = Mechanics badge.orders = Orders home.requirements.label = Requirements +home.title.label = Test project "Car Repair Service" client.title = Clients mechanic.title = Mechanics order.title = Orders +lang.en = English +lang.ru = Russian + firstName.label = First Name middleName.label = Middle Name lastName.label = Last Name diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index 1f94d21..f17ad71 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -5,11 +5,15 @@ badge.mechanics = Mechanics badge.orders = Orders home.requirements.label = Requirements +home.title.label = Test project "Car Repair Service" client.title = Clients mechanic.title = Mechanics order.title = Orders +lang.en = English +lang.ru = Russian + firstName.label = First Name middleName.label = Middle Name lastName.label = Last Name diff --git a/src/main/resources/messages_ru.properties b/src/main/resources/messages_ru.properties index 3abf531..08f0638 100644 --- a/src/main/resources/messages_ru.properties +++ b/src/main/resources/messages_ru.properties @@ -5,11 +5,15 @@ badge.mechanics = Механики badge.orders = Заказы home.requirements.label = Требования +home.title.label = Тестовый проект "Автомастерская" client.title = Клиенты mechanic.title = Механики order.title = Заказы +lang.en = Английский +lang.ru = Русский + firstName.label = Имя middleName.label = Отчество lastName.label = Фамилия diff --git a/src/main/resources/static/images/ru.png b/src/main/resources/static/images/ru.png new file mode 100755 index 0000000000000000000000000000000000000000..47da4214fd9edb383687c1d4f84fe8b42a51ceb2 GIT binary patch literal 420 zcmV;V0bBlwP)X|NRSO0LlM<{-BURBqYRGSojej zfLOL~|EH_V_~;P>Nc10*D0|Jxss< zFi1)Q<$$6LU}rIc*dU*QNFV}+9T))>0|XG`SD?F)5CbX~O$rDA0t^5@iDe$xIAIn5 O0000{qW|y?pud`Sa)3|NY&vWd%S0u>b>P!2!lUe;6EF*#G_c zFVXVt@6Q{uX@40W{p0iY2Aa+A^Cu7i8KT+YH}2j52q4BskM2rJ$^k9;2Xxc_|Np=M z&VaLlA*IO5FlECMfB<5VUNC{tBZO(|zW*;@GJN;|bTJ71`0*d;`d`2P!x=ymOA`2> z+y@9C##^^8%gd{MW@Y91_2d742B2~OQNf=-zkmD?Vqkdk_wPTUNeuu2#KPTG{_;O4 v7C%8E5*DLB7#Kb?Fnj}}-(W6879hX?8lYRg`Y`<~00000NkvXXu0mjfD6Jtx literal 0 HcmV?d00001 diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index c9484e2..16f4b98 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -6,13 +6,13 @@
-

Car Repair test project

+

:

- Requirements +
diff --git a/src/main/resources/templates/main.html b/src/main/resources/templates/main.html index daaaad2..d35df31 100644 --- a/src/main/resources/templates/main.html +++ b/src/main/resources/templates/main.html @@ -35,6 +35,14 @@ + diff --git a/src/main/resources/templates/order/index.html b/src/main/resources/templates/order/index.html index 70c070b..39bd356 100644 --- a/src/main/resources/templates/order/index.html +++ b/src/main/resources/templates/order/index.html @@ -81,7 +81,7 @@ - +