Commit 0eae5882 authored by Quxl's avatar Quxl

优化国际化配置

parent 3c9f700f
......@@ -115,7 +115,7 @@ public class MemberOpenApiController {
@PostMapping("getLocale")
@ApiOperation("获取当前语言环境")
public Object getLocale(HttpServletRequest request) {
return Rjx.jsonOk().setMessage(LocaleContextHolder.getLocale().toString());
return Rjx.jsonOk().set("locale", LocaleContextHolder.getLocale().toString()).set("msg.test", messages.get("msg.test"));
}
}
......@@ -20,7 +20,8 @@ public class DefaultMessages implements Messages {
public String get(String name, String... args) {
try {
Locale locale = LocaleContextHolder.getLocale();
return messageSource.getMessage(name, args, locale == null ? Locale.CHINA : locale);
locale = locale == null ? Locale.CHINA : locale;
return messageSource.getMessage(name, args, locale);
} catch (NoSuchMessageException e) {
return name;
} catch (Exception e) {
......
package com.egolm.film.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
@ConfigurationProperties(prefix = "spring.messages")
@Configuration
public class LocaleConfig {
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("/i18n/messages");
messageSource.setBasename("i18n/messages");
messageSource.setDefaultEncoding("utf-8");
messageSource.setAlwaysUseMessageFormat(true);
messageSource.setCacheSeconds(-1);
......
......@@ -13,8 +13,6 @@ spring.http.encoding.force=true
spring.http.encoding.enabled=true
spring.http.encoding.charset=utf-8
spring.messages.basename=classpath:i18n/messages
com.egolm.film.email.smtp.host=mail.egolm.com
com.egolm.film.email.smtp.port=25
com.egolm.film.email.smtp.is_auth=true
......
email.getPassword.subject=\u4E2D\u56FD\u7535\u5F71\u8282[\u627E\u56DE\u5BC6\u7801]\u90AE\u4EF6
email.getPassword.content={0}, \u60A8\u597D, \u60A8\u7684\u65B0\u5BC6\u7801\u662F: [{1}]
sys.err=\u7CFB\u7EDF\u9519\u8BEF
sys.err.user_disabled=\u7528\u6237\u5DF2\u7ECF\u7981\u7528
sys.err.user_pwd_err=\u7528\u6237\u6216\u5BC6\u7801\u9519\u8BEF
sys.err.user_pwd_null=\u7528\u6237\u540D\u548C\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A
msg.hello=\u60A8\u597D
msg.your_pwd=\u60A8\u7684\u5BC6\u7801\u662F
\ No newline at end of file
email.getPassword.subject=China Film Festival [retrieve password] email
email.getPassword.content=Hello {0}, Your password is: [{1}]
sys.err=System error
sys.err.user_disabled=User disabled
sys.err.user_pwd_err=User or password error
sys.err.user_pwd_null=User and passowrd can not be null
msg.test=Test
\ No newline at end of file
......@@ -6,5 +6,4 @@ sys.err.user_disabled=\u7528\u6237\u5DF2\u7ECF\u7981\u7528
sys.err.user_pwd_err=\u7528\u6237\u6216\u5BC6\u7801\u9519\u8BEF
sys.err.user_pwd_null=\u7528\u6237\u540D\u548C\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A
msg.hello=\u60A8\u597D
msg.your_pwd=\u60A8\u7684\u5BC6\u7801\u662F
\ No newline at end of file
msg.test=\u6D4B\u8BD5
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment