Commit c17a0b70 authored by Quxl's avatar Quxl

增加国际化配置

parent 1f81f6df
package com.egolm.film; package com.egolm.film;
import java.util.Locale;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
...@@ -18,6 +21,7 @@ public class FilmApplication { ...@@ -18,6 +21,7 @@ public class FilmApplication {
private static ApplicationContext applicationContext; private static ApplicationContext applicationContext;
public static void main(String[] args) { public static void main(String[] args) {
LocaleContextHolder.setDefaultLocale(Locale.CHINA);
applicationContext = SpringApplication.run(FilmApplication.class, args); applicationContext = SpringApplication.run(FilmApplication.class, args);
} }
......
package com.egolm.film.messages;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import com.egolm.film.config.XException;
@Component
public class DefaultMessages implements Messages {
@Autowired
protected MessageSource messageSource;
public String get(String name, String... args) {
try {
return messageSource.getMessage(name, args, LocaleContextHolder.getLocale());
} catch (NoSuchMessageException e) {
return name;
} catch (Exception e) {
throw new XException("", e);
}
}
}
package com.egolm.film.messages;
public interface Messages {
public String get(String name, String... args);
}
...@@ -13,3 +13,6 @@ spring.http.encoding.force=true ...@@ -13,3 +13,6 @@ spring.http.encoding.force=true
spring.http.encoding.enabled=true spring.http.encoding.enabled=true
spring.http.encoding.charset=utf-8 spring.http.encoding.charset=utf-8
spring.messages.basename=classpath:i18n/messages
spring.messages.cache-seconds=3600
spring.messages.encoding=UTF-8
\ 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