From a739f69d1a0bab014c9d63bf40c82923778255ac Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 24 Nov 2020 09:42:49 +0300 Subject: Fix title localization on some web pages --- src/main/java/com/juick/www/controllers/Site.java | 28 +++++++++++++++-------- src/main/resources/messages.properties | 1 + src/main/resources/messages_ru.properties | 1 + 3 files changed, 21 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/main/java/com/juick/www/controllers/Site.java b/src/main/java/com/juick/www/controllers/Site.java index 4aa82f1a..0cc0abfe 100644 --- a/src/main/java/com/juick/www/controllers/Site.java +++ b/src/main/java/com/juick/www/controllers/Site.java @@ -30,12 +30,17 @@ import com.juick.util.MessageUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.text.StringEscapeUtils; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.CookieValue; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; @@ -44,7 +49,9 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.Optional; +import java.util.ResourceBundle; import java.util.stream.Collectors; /** @@ -106,33 +113,36 @@ public class Site { String title; List mids; + Locale locale = LocaleContextHolder.getLocale(); + if (paramSearch != null) { - title = "Поиск: " + StringEscapeUtils.escapeHtml4(paramSearch); + String searchTitle = ResourceBundle.getBundle("messages", locale).getString("title.search"); + title = searchTitle + StringEscapeUtils.escapeHtml4(paramSearch); mids = messagesService.getSearch(visitor, WebUtils.encodeSphinx(paramSearch), page); } else if (paramShow == null) { - title = "Обсуждения"; + title = ResourceBundle.getBundle("messages", locale).getString("link.discuss"); mids = messagesService.getDiscussions(visitor.getUid(), paramTo); } else if (paramShow.equals("top")) { - title = "Популярные"; + title = ResourceBundle.getBundle("messages", locale).getString("link.popular"); mids = messagesService.getPopular(visitor.getUid(), paramBefore); model.addAttribute("discover", true); } else if (paramShow.equals("my") && !visitor.isAnonymous()) { - title = "Моя лента"; + title = ResourceBundle.getBundle("messages", locale).getString("link.my"); mids = messagesService.getMyFeed(visitor.getUid(), paramBefore, true); } else if (paramShow.equals("private") && !visitor.isAnonymous()) { - title = "Приватные"; + title = ResourceBundle.getBundle("messages", locale).getString("link.privateMessages"); mids = messagesService.getPrivate(visitor.getUid(), paramBefore); } else if (paramShow.equals("discuss")) { return "redirect:/"; } else if (paramShow.equals("recommended") && !visitor.isAnonymous()) { - title = "Рекомендации"; + title = ResourceBundle.getBundle("messages", locale).getString("link.recommended"); mids = messagesService.getRecommended(visitor.getUid(), paramBefore); } else if (paramShow.equals("photos")) { - title = "Фотографии"; + title = ResourceBundle.getBundle("messages", locale).getString("link.withPhotos"); mids = messagesService.getPhotos(visitor.getUid(), paramBefore); model.addAttribute("discover", true); } else if (paramShow.equals("all")) { - title = "Все сообщения"; + title = ResourceBundle.getBundle("messages", locale).getString("link.allMessages"); mids = messagesService.getAll(visitor.getUid(), paramBefore); model.addAttribute("discover", true); } else { diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 116006e3..60ddcf08 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -82,6 +82,7 @@ title.help=Help title.loginOrSignup=Juick - Log In or Sign Up title.index.anonym=Juick microblogs: popular posts title.index.user=Popular +title.search=Search: error.pageNotFound=Page not found error.pageNotFound.description=User probably deleted this post, or this page never existed. diff --git a/src/main/resources/messages_ru.properties b/src/main/resources/messages_ru.properties index 436f1e1d..acbef7a9 100644 --- a/src/main/resources/messages_ru.properties +++ b/src/main/resources/messages_ru.properties @@ -80,6 +80,7 @@ title.help=Справка title.loginOrSignup=Juick - Войдите в систему или зарегистрируйтесь title.index.anonym=Микроблоги Juick: популярные записи title.index.user=Популярные +title.search=Поиск: error.pageNotFound=Страница не найдена error.pageNotFound.description=Сожалеем, но страницу с этим адресом удалил её автор, либо её никогда не существовало. -- cgit v1.2.3