use of org.springframework.context.support.ResourceBundleMessageSource in project datagear by datageartech.
the class CoreConfig method messageSource.
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource bean = new ResourceBundleMessageSource();
bean.setBasename("org.datagear.web.i18n.message");
bean.setDefaultEncoding(IOUtil.CHARSET_UTF_8);
// i18n找不到指定语言的bundle时不使用操作系统默认语言重新查找,直接使用默认bundle。
// 系统目前只有默认bundle(无后缀)、英语bundle("en"后缀),如果设置为true(默认值),
// 当操作系统语言是英语时,会导致切换语言不起作用,i18n始终会被定位至英语bundle
bean.setFallbackToSystemLocale(false);
return bean;
}
use of org.springframework.context.support.ResourceBundleMessageSource in project n2o-framework by i-novus-llc.
the class DataControllerTestBase method setUp.
@Before
public void setUp() {
N2oEnvironment environment = new N2oEnvironment();
environment.setNamespacePersisterFactory(new PersisterFactoryByMap());
environment.setNamespaceReaderFactory(new ReaderFactoryByMap());
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasenames("n2o_messages", "messages");
messageSource.setDefaultEncoding("UTF-8");
environment.setMessageSource(new MessageSourceAccessor(messageSource));
OverrideProperties properties = PropertiesReader.getPropertiesFromClasspath("META-INF/n2o.properties");
properties.put("n2o.engine.mapper", "spel");
SimplePropertyResolver propertyResolver = new SimplePropertyResolver(properties);
setUpStaticProperties(propertyResolver);
environment.setSystemProperties(propertyResolver);
builder = new N2oApplicationBuilder(environment);
configure(builder);
CompileInfo.setSourceTypes(builder.getEnvironment().getSourceTypeRegister());
}
use of org.springframework.context.support.ResourceBundleMessageSource in project n2o-framework by i-novus-llc.
the class IOProcessorTest method testProps.
@Test
public void testProps() throws Exception {
// test properties
ReaderFactoryByMap readerFactory = new ReaderFactoryByMap();
readerFactory.register(new BodyNamespaceEntityIO());
IOProcessorImpl p = new IOProcessorImpl(readerFactory);
Properties properties = new Properties();
properties.setProperty("testProp1", "testProp1");
PropertyResolver systemProperties = new SimplePropertyResolver(properties);
p.setSystemProperties(systemProperties);
testElementWithProperty(p, "testProp1");
// test params
HashMap<String, String> params = new HashMap<>();
params.put("testProp1", "testProp2");
p = new IOProcessorImpl(readerFactory);
try {
MetadataParamHolder.setParams(params);
testElementWithProperty(p, "testProp2");
} finally {
MetadataParamHolder.setParams(null);
}
// test messages
p = new IOProcessorImpl(readerFactory);
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasenames("test_messages");
messageSource.setDefaultEncoding("UTF-8");
p.setMessageSourceAccessor(new MessageSourceAccessor(messageSource));
testElementWithProperty(p, "testProp3");
// test override
p = new IOProcessorImpl(readerFactory);
p.setSystemProperties(systemProperties);
p.setMessageSourceAccessor(new MessageSourceAccessor(messageSource));
try {
MetadataParamHolder.setParams(params);
// самый приоритетный params
testElementWithProperty(p, "testProp2");
} finally {
MetadataParamHolder.setParams(null);
}
// test fail fast
p = new IOProcessorImpl(readerFactory);
p.setFailFast(true);
// p.setSystemProperties(systemProperties); not set to fail
try {
testElementWithProperty(p, "testProp1");
fail();
} catch (N2oException ignored) {
}
// test fail tolerance
p = new IOProcessorImpl(readerFactory);
p.setFailFast(false);
// p.setSystemProperties(systemProperties); not set to fail
try {
Element in = dom("net/n2oapp/framework/config/io/ioprocessor22.xml");
BaseEntity baseEntity = new BaseEntity();
p.element(in, "attr", baseEntity::getAttr, baseEntity::setAttr);
assertThat(baseEntity.getAttr(), equalTo("${testProp1}"));
} catch (N2oException e) {
fail();
}
}
use of org.springframework.context.support.ResourceBundleMessageSource in project n2o-framework by i-novus-llc.
the class N2oTestBase method setUp.
public void setUp() throws Exception {
N2oEnvironment environment = new N2oEnvironment();
environment.setNamespacePersisterFactory(new PersisterFactoryByMap());
environment.setNamespaceReaderFactory(new ReaderFactoryByMap());
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.addBasenames("n2o_api_messages", "n2o_api_messages", "n2o_config_messages", "test_messages", "messages");
messageSource.setDefaultEncoding("UTF-8");
Locale locale = new Locale("ru");
LocaleContextHolder.setLocale(locale);
environment.setMessageSource(new MessageSourceAccessor(messageSource));
OverrideProperties n2oProperties = PropertiesReader.getPropertiesFromClasspath("META-INF/n2o.properties");
OverrideProperties appProperties = PropertiesReader.getPropertiesFromClasspath("application.properties");
appProperties.setBaseProperties(n2oProperties);
environment.setSystemProperties(new SimplePropertyResolver(appProperties));
builder = new N2oApplicationBuilder(environment);
configure(builder);
CompileInfo.setSourceTypes(builder.getEnvironment().getSourceTypeRegister());
}
use of org.springframework.context.support.ResourceBundleMessageSource in project SpringMVCFinal by tonysodeep.
the class WebAppContextConfig method messageSource.
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource msg = new ResourceBundleMessageSource();
msg.setBasename("messages");
return msg;
}
Aggregations