Commit 12ce8052 authored by Quxl's avatar Quxl

修改国际化语言工具

parent c17a0b70
package com.egolm.film.messages; package com.egolm.film.messages;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.NoSuchMessageException; import org.springframework.context.NoSuchMessageException;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.servlet.support.RequestContextUtils;
import com.egolm.film.config.WebMvcConfig;
import com.egolm.film.config.XException; import com.egolm.film.config.XException;
@Component @Component
...@@ -16,7 +21,9 @@ public class DefaultMessages implements Messages { ...@@ -16,7 +21,9 @@ public class DefaultMessages implements Messages {
public String get(String name, String... args) { public String get(String name, String... args) {
try { try {
return messageSource.getMessage(name, args, LocaleContextHolder.getLocale()); HttpServletRequest request = WebMvcConfig.getRequest();
Locale locale = RequestContextUtils.getLocale(request);
return messageSource.getMessage(name, args, locale == null ? Locale.CHINA : locale);
} catch (NoSuchMessageException e) { } catch (NoSuchMessageException e) {
return name; return name;
} catch (Exception e) { } catch (Exception e) {
......
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