use of cn.taketoday.web.i18n.FixedLocaleResolver in project today-framework by TAKETODAY.
the class ViewResolverTests method internalResourceViewResolverWithJstlAndContextParam.
@Test
public void internalResourceViewResolverWithJstlAndContextParam() throws Exception {
Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;
this.sc.addInitParameter(Config.FMT_LOCALIZATION_CONTEXT, "cn/taketoday/web/context/WEB-INF/context-messages");
this.wac.addMessage("code1", locale, "messageX");
this.wac.refresh();
InternalResourceViewResolver vr = new InternalResourceViewResolver();
vr.setViewClass(JstlView.class);
vr.setApplicationContext(wac);
View view = vr.resolveViewName("example1", Locale.getDefault());
assertThat(view).isInstanceOf(JstlView.class);
assertThat(((JstlView) view).getUrl()).as("Correct URL").isEqualTo("example1");
view = vr.resolveViewName("example2", Locale.getDefault());
assertThat(view).isInstanceOf(JstlView.class);
assertThat(((JstlView) view).getUrl()).as("Correct URL").isEqualTo("example2");
wac.registerSingleton(LocaleResolver.BEAN_NAME, new FixedLocaleResolver(locale));
Map<String, Object> model = new HashMap<>();
TestBean tb = new TestBean();
model.put("tb", tb);
view.render(model, this.requestContext);
assertThat(tb.equals(this.request.getAttribute("tb"))).as("Correct tb attribute").isTrue();
assertThat(this.request.getAttribute("rc") == null).as("Correct rc attribute").isTrue();
assertThat(Config.get(this.request, Config.FMT_LOCALE)).isEqualTo(locale);
LocalizationContext lc = (LocalizationContext) Config.get(this.request, Config.FMT_LOCALIZATION_CONTEXT);
assertThat(lc.getResourceBundle().getString("code1")).isEqualTo("message1");
assertThat(lc.getResourceBundle().getString("code2")).isEqualTo("message2");
}
use of cn.taketoday.web.i18n.FixedLocaleResolver in project today-framework by TAKETODAY.
the class ViewResolverTests method internalResourceViewResolverWithJstl.
@Test
public void internalResourceViewResolverWithJstl() throws Exception {
Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;
this.wac.addMessage("code1", locale, "messageX");
this.wac.refresh();
InternalResourceViewResolver vr = new InternalResourceViewResolver();
vr.setViewClass(JstlView.class);
vr.setApplicationContext(this.wac);
View view = vr.resolveViewName("example1", Locale.getDefault());
assertThat(view).isInstanceOf(JstlView.class);
assertThat(((JstlView) view).getUrl()).as("Correct URL").isEqualTo("example1");
view = vr.resolveViewName("example2", Locale.getDefault());
assertThat(view).isInstanceOf(JstlView.class);
assertThat(((JstlView) view).getUrl()).as("Correct URL").isEqualTo("example2");
this.wac.registerSingleton(LocaleResolver.BEAN_NAME, new FixedLocaleResolver(locale));
Map<String, Object> model = new HashMap<>();
TestBean tb = new TestBean();
model.put("tb", tb);
view.render(model, this.requestContext);
assertThat(tb.equals(this.request.getAttribute("tb"))).as("Correct tb attribute").isTrue();
assertThat(this.request.getAttribute("rc") == null).as("Correct rc attribute").isTrue();
assertThat(Config.get(this.request, Config.FMT_LOCALE)).isEqualTo(locale);
LocalizationContext lc = (LocalizationContext) Config.get(this.request, Config.FMT_LOCALIZATION_CONTEXT);
assertThat(lc.getResourceBundle().getString("code1")).isEqualTo("messageX");
}
use of cn.taketoday.web.i18n.FixedLocaleResolver in project today-framework by TAKETODAY.
the class WebMvcAutoConfiguration method localeResolver.
@Component
@ConditionalOnMissingBean(name = LocaleResolver.BEAN_NAME)
public LocaleResolver localeResolver() {
if (this.webProperties.getLocaleResolver() == WebProperties.LocaleResolver.FIXED) {
return new FixedLocaleResolver(this.webProperties.getLocale());
}
AcceptHeaderLocaleResolver localeResolver = new AcceptHeaderLocaleResolver();
localeResolver.setDefaultLocale(this.webProperties.getLocale());
return localeResolver;
}
use of cn.taketoday.web.i18n.FixedLocaleResolver in project today-infrastructure by TAKETODAY.
the class WebMvcAutoConfiguration method localeResolver.
@Component
@ConditionalOnMissingBean(name = LocaleResolver.BEAN_NAME)
public LocaleResolver localeResolver() {
if (this.webProperties.getLocaleResolver() == WebProperties.LocaleResolver.FIXED) {
return new FixedLocaleResolver(this.webProperties.getLocale());
}
AcceptHeaderLocaleResolver localeResolver = new AcceptHeaderLocaleResolver();
localeResolver.setDefaultLocale(this.webProperties.getLocale());
return localeResolver;
}
use of cn.taketoday.web.i18n.FixedLocaleResolver in project today-infrastructure by TAKETODAY.
the class ViewResolverTests method internalResourceViewResolverWithJstlAndContextParam.
@Test
public void internalResourceViewResolverWithJstlAndContextParam() throws Exception {
Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;
this.sc.addInitParameter(Config.FMT_LOCALIZATION_CONTEXT, "cn/taketoday/web/context/WEB-INF/context-messages");
this.wac.addMessage("code1", locale, "messageX");
this.wac.refresh();
InternalResourceViewResolver vr = new InternalResourceViewResolver();
vr.setViewClass(JstlView.class);
vr.setApplicationContext(wac);
View view = vr.resolveViewName("example1", Locale.getDefault());
assertThat(view).isInstanceOf(JstlView.class);
assertThat(((JstlView) view).getUrl()).as("Correct URL").isEqualTo("example1");
view = vr.resolveViewName("example2", Locale.getDefault());
assertThat(view).isInstanceOf(JstlView.class);
assertThat(((JstlView) view).getUrl()).as("Correct URL").isEqualTo("example2");
wac.registerSingleton(LocaleResolver.BEAN_NAME, new FixedLocaleResolver(locale));
Map<String, Object> model = new HashMap<>();
TestBean tb = new TestBean();
model.put("tb", tb);
view.render(model, this.requestContext);
assertThat(tb.equals(this.request.getAttribute("tb"))).as("Correct tb attribute").isTrue();
assertThat(this.request.getAttribute("rc") == null).as("Correct rc attribute").isTrue();
assertThat(Config.get(this.request, Config.FMT_LOCALE)).isEqualTo(locale);
LocalizationContext lc = (LocalizationContext) Config.get(this.request, Config.FMT_LOCALIZATION_CONTEXT);
assertThat(lc.getResourceBundle().getString("code1")).isEqualTo("message1");
assertThat(lc.getResourceBundle().getString("code2")).isEqualTo("message2");
}
Aggregations