powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / Spring web mvc i18n не показывает перевод ?!
7 сообщений из 7, страница 1 из 1
Spring web mvc i18n не показывает перевод ?!
    #39122467
Atum1
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Есть веб проект
...
Рейтинг: 0 / 0
Spring web mvc i18n не показывает перевод ?!
    #39122468
Atum1
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Atum1Есть веб проект

https://github.com/isalnikov/SecurityProvider
...
Рейтинг: 0 / 0
Spring web mvc i18n не показывает перевод ?!
    #39122470
Atum1
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
хочу добавить i18n интернализацию

в тесте все отлично работает ... в jsp нет


about.jsp

Код: java
1.
 <spring:message code="hello" /></p>



Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
@Controller
public class MessageController {

    @Autowired
    private MessageHelper messageHelper;
    
    @Autowired
    private MessageSource messageSource;

    @RequestMapping(value = {"/message/{code}"},
            method = RequestMethod.GET)
    @ResponseBody
    public String index(@PathVariable("code") String code, Locale locale) {
        
        String result = messageSource.getMessage(code, new Object[]{}, locale);
        System.out.println(String.format("%s  :  %s", locale.getLanguage(), result));
        
        return String.format("%s  :  %s", locale.getLanguage(), messageHelper.getMessage(code));

    }

}



Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/favicon.ico").addResourceLocations("/favicon.ico").setCachePeriod(CACHE_PERIOD);
        registry.addResourceHandler("/media/**/*.{js,html,css}").addResourceLocations("/media/").setCachePeriod(CACHE_PERIOD);
        registry.addResourceHandler("/resources/").addResourceLocations("/resources/**").setCachePeriod(CACHE_PERIOD);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
        interceptor.setParamName("language");

        registry.addInterceptor(interceptor);

    }

    @Bean(name = "jspViewResolver")
    public InternalResourceViewResolver jspViewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/jsp/");
        resolver.setSuffix(".jsp");
        resolver.setViewClass(JstlView.class);
        resolver.setOrder(1);
        return resolver;
    }

    @Bean
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setUseCodeAsDefaultMessage(true);
        messageSource.setDefaultEncoding("UTF-8");
        messageSource.setBasenames("message");
        messageSource.setCacheSeconds(5);
        messageSource.setFallbackToSystemLocale(false);// ???
        
        
        System.out.println("+++++++++++++++ " + messageSource.getMessage("hello", new Object[]{}, Locale.getDefault() ));
        
        return messageSource;
    }

    @Bean
    public LocaleResolver localeResolver() {
        CookieLocaleResolver localeResolver = new CookieLocaleResolver();
        localeResolver.setDefaultLocale(new Locale("ru")); // change this Locale.ENGLISH)
        localeResolver.setCookieName("terminal_cookie");
        localeResolver.setCookieMaxAge(60 * 30);
        return localeResolver;
    }



Запрос на http://localhost:8080/message/hello?language=en

но перевода так же нет ...
...
Рейтинг: 0 / 0
Spring web mvc i18n не показывает перевод ?!
    #39122559
Atum1
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
...
Рейтинг: 0 / 0
Spring web mvc i18n не показывает перевод ?!
    #39122564
Atum1
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
веб контейнер jetty
...
Рейтинг: 0 / 0
Spring web mvc i18n не показывает перевод ?!
    #39122586
Фотография mayton
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Atum1, у меня твой урл не открывается http://localhost:8080/message/hello?language=en
...
Рейтинг: 0 / 0
Spring web mvc i18n не показывает перевод ?!
    #39122602
Atum1
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
maytonAtum1, у меня твой урл не открывается http://localhost:8080/message/hello?language=en



забыл указать в конфиге :
Код: java
1.
 messageSource.setBasenames("message");



classpath - добавил и все заработало

Код: java
1.
 messageSource.setBasenames("classpath:message");
...
Рейтинг: 0 / 0
7 сообщений из 7, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / Spring web mvc i18n не показывает перевод ?!
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]