将 .strings 文件转换为 .strings.json 文件

为了支持更广泛的语言配置并改进 Looker 项目中的字符串管理,请将 .strings 文件转换为 .strings.json 格式。这种现代化有助于您利用增强的本地化功能,让不同语言区域的用户能够更轻松高效地使用数据应用。本指南提供了迁移现有文件的步骤。

如需将 .strings 文件转换为 .strings.json 文件,请执行以下操作:

  1. 如果您使用的是 7.12 之前的 Looker 版本,请关闭用于本地化的旧版 .strings 文件旧版功能。
  2. 点击项目文件列表右上角的 + 图标,然后选择创建语言区域字符串文件,为项目创建一个新的 .strings.json 文件。
  3. 为新的 .strings.json 文件命名。.strings 文件的标题必须与使用相应语言区域的用户或群组所分配的语言区域代码相匹配,并且默认语言区域文件的标题必须与项目清单文件default_locale 的值相匹配。
  4. .strings.json 文件中显示的代码段提供了 JSON 格式设置示例。删除此示例,并将其替换为一对大括号:{}
  5. 从旧 .strings 文件中复制键值对,并将其粘贴到大括号内。
  6. 将所有等号替换为英文冒号。
  7. 移除所有注释;或将注释重新格式化为单个注释或注释数组,如下所示。
  8. 将所有半角分号替换为半角逗号。

键值对的典型 .strings.json 格式如下所示:

{
    "flight_info" : "Flight Info",
    "id" : "Identifier",
    "airline" : "Air Carrier"
}

您可以使用以下格式设置注释的格式:

{
    " My Comment": {
        "my_comment_array": [
        "The name of this file should be the associated locale code followed by '.strings.json'",
        "There is one .strings.json file per locale.",
        "Define your translated strings one key at a time",
        "Keys can be any string; choose whatever scheme helps you stay organized",
        "Then, set your Lookml label and description parameters to the desired key values.",
        "To choose this file as the master key list and as the one to validate against",
        "set its locale code ('test') as the default_locale in the manifest file"
        ],
        "value": "Translation for My Comment"
    },
    "My Key": {
        "value": "Translation for My Key",
        "comment": "Define your translated strings with a comment or an array of comments"
    }
}