%E5%9B%BD%E9%99%85%E5%8C%96%E6%94%AF%E6%8C%81 - MinMinGuGu/GuGu_Blog_Sync GitHub Wiki
- 添加自己的国际化文件及内容
- 添加配置
core-config:
i18n:
lang: zh_CN #en_US #
name: message.messages # 国际化文件名称
- 测试接口
@RestController
@RequestMapping("test")
public class TestController {
@Autowired
I18nUtils i18nUtils;
@GetMapping
public String testI18n(@RequestParam String code){
return i18nUtils.getI18nMessage(code == null || "".equals(code)? "test_example" : code);
}
@GetMapping("lang")
public String testI18nLang(@RequestParam String code, @RequestParam String lang){
return i18nUtils.getI18nMessageByLang(code == null || "".equals(code)? "test_example" : code, lang);
}
}
- 访问接口获取国际化信息
# 切换配置验证
# core-config.i18n.lang=zh_CN
# core-config.i18n.lang=en_US
http://localhost:9091/test?code=test_example
# 指定语言环境
http://localhost:9091/test/lang?code=test_example&&lang=zh_CN
http://localhost:9091/test/lang?code=test_example&&lang=en_US
修改配置
指定语言环境