Spring Boot 菜鸟教程 15 页面国际化

本文介绍了如何在Spring Boot项目中实现页面国际化,包括创建`messages.properties`和`messages_zh_CN.properties`文件,设置启动类注解,以及处理中文和英文语言页面的切换。此外,还提供了源码地址和相关项目的链接。
摘要由CSDN通过智能技术生成

GitHub

src="//ghbtns.com/github-btn.html?user=je-ge&repo=spring-boot&type=watch&count=true" scrolling="0" width="110" height="20">

internationalization(i18n)

  • 国际化(internationalization)是设计和制造容易适应不同区域要求的产品的一种方式。
  • 它要求从产品中抽离所有地域语言,国家/地区和文化相关的元素。
  • 换言之,应用程序的功能和代码设计考虑在不同地区运行的需要,其代码简化了不同本地版本的生产。
  • 开发这样的程序的过程,就称为国际化。

中文语言页面

这里写图片描述

英文语言页面

这里写图片描述

浏览器切换中文,英文

这里写图片描述

启动类Application添加额外注解

package com.jege.spring.boot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;

/**
 * @author JE哥
 * @email 1272434821@qq.com
 * @description:spring boot 启动类
 */

@SpringBootApplication
@PropertySources(value = { @PropertySource("classpath:messages.properties") })
public class Application {
   

  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }

}

messages.properties

同messages_en_US.properties

title=User Management
id=Id
name=Name
age=Age
userinfo=UserInfo

q=Keyword
add=Add
edit=Edit
remove=Remove
reload=Reload
search=Search
save=Save
cancel=Cancel

errorMessage=Error Message
addUser=Add User
editUser=Edit User

operationMessage=Operation Message
editSelete=Please select a row of data in the modification
deleteSelete=Please select a row of data in the delete

messages_zh_CN.properties

title=\u7528\u6237\u7BA1\u7406
id=\u7F16\u53F7
name=\u4E0B\u9762
age=\u5E74\u9F84
userinfo=\u7528\u6237\u4FE1\u606F

q=\u5173\u952E\u5B57
add=\u6DFB\u52A0
edit=\u7F16\u8F91
remove=\u5220\u9664
reload=\u5237\u65B0
search=\u641C\u7D22
save=\u4FDD\u5B58
cancel=\u53D6\u6D88

errorMessage=\u9519\u8BEF\u63D0\u793A
addUser=\u6DFB\u52A0\u7528\u6237
editUser=\u7F16\u8F91\u7528\u6237
operationMessage=\u64CD\u4F5C\u63D0\u793A
editSelete=\u8BF7\u5148\u9009\u4E2D\u4E00\u884C\u6570\u636E\uFF0C\u5728\u4FEE\u6539\uFF01\uFF01\uFF01
deleteSelete=\u8BF7\u5148\u9009\u4E2D\u4E00\u884C\u6570
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值