Intellij IDEA Resource Bundle

Resource Bundle是什么

能够直接经过官方的描述来了解 https://www.jetbrains.com/hel...html

Resource bundle is a set of properties files that have same base name with different language-specific suffixes. A resource bundle contains at least two properties files with similar base name, for example file_en.properties and file_de.properties.

官方的描述是一堆有着相同前缀名称但有着不一样语言后缀名称的属性文件的集合,且至少包含2个有着类似前缀名称的属性文件,例如file_en.propertiesfile_de.properties
其实从字面上理解就是资源包,为了方便统一管理繁多的国际化文件java

Resource Bundle的目录结构
Resource Bundles目录结构ide

只是在Intellij IDEA内显示上多了一层名为Resources的Resource Bundle目录,但在实际物理目录下Resources*.properties等文件仍在java-calculator目录下工具

建立Resource Bundle

  • Alt + 1 打开项目工具窗口,选中要建立Resource Bundle的目录
  • Alt + Insert - Resource Bundle
    或者主菜单 - File - New - Resource Bundle
    或者当前目录右键 - New - Resource Bundle
    来打开建立Resource Bundle的对话框
  • 填写Resource Bundle的基础名称
    勾选User XML-based properties files则会建立XML格式的属性文件
    Project locale表示项目里已经存在的区域
    Locales to add表示添加相应的区域,添加右边的+号便可添加,多个区域用,隔开
  • 以建立一个基础名称为demo的Resource Bundle为例

建立Resource Bundle

点击+号添加多个区域,这里以添加zh和en为例
添加区域idea

添加完成后,能够在Locales to add看到已经添加的区域
添加区域后spa

点击OK生成Resource Bundle
生成Resource Bundlecode

合并或拆分Resource Bundle

  • 添加新的属性文件:直接在Resource Bundle 'demo'目录右键 - Add Property Files to Resource Bundle,点击+添加新的区域便可生成新的属性文件
  • 拆分:若是不想使用Resource Bundle管理属性文件,能够在Resource Bundle目录右键 - Dissociate Resource Bundle 'demo'
  • 合并:在同一个目录下建立多个符合相同前缀、不一样语言后缀名称的属性文件时,Intellij IDEA会自动建立Resource Bundle管理这些文件
    也能够手动组合属性文件,按住Ctrl + 鼠标左键选中多个属性文件后右键 - Combine to Resource Bundle
相关文章
相关标签/搜索