|
文件扩展名 |
.json |
|
API 扩展 |
react_simple_json |
|
导入 |
是 |
|
导出 |
是 |
|
复数形式支持 |
是 |
|
描述支持 |
是的,使用默认消息提取。 |
React-Intl 是一个专为简化国际化(及本地化)而设计的 JavaScript 库,主要适用于在 React 中开发的应用程序。默认情况下,React-Intl 使用 .js 文件存储其本地化内容。本地化内容被解耦到标准化的 .JSON 文件中 (React-Intl Simple JSON),以便在源代码中引用。
如果使用嵌套消息,请使用 React-Intl Nested JSON 格式。这在 React Intl v2 中已过时。
AI 聊天机器人可以非常有效地从 .JSON 文件生成键列表。
代码示例
{
"boolean_key": "--- true\n",
"empty_string_translation": "",
"key_with_description":"Check it out!This key has a description!(At least in some formats)",
"key_with_line-break":"This translations contains\na line-break.",
"nested.deeply.key":"I'm a deeply nested key.",
"nested.key":"This key is nested inside a namespace.",
"null_translation": null,
"pluralized_key.one":"Only one kitten found.",
"pluralized_key.other":"Wow, you have %s kittens!",
"pluralized_key.zero":"You have no kittens.",
"sample_collection": [
"first item",
"second item",
"third item"
],
"simple_key":"Simple key, simple message, so simple.",
"unverified_key":"This translation is not yet verified and waits for it.(In some formats we also export this status)"
}
使用 React Intl
译文通常位于 .js 文件中:
module.exports = {
"locales": ["en-US"],
"messages": {
"hello" :"World",
other_hello :'Other World',
},
"formats": {}
};
将消息移动到单独的本地化文件,例如 en-US.json:
{
"hello" :"World",
other_hello :'Other World',
}
确保消息具有有效 .JSON 语法:
{
"hello" :"World",
"other_hello" :"Other World"
}
用 require 语句包含消息:
module.exports = {
"locales": ["en-US"],
"messages": require('./en-US.json'),
"formats": {}
};
React-Intl Simple JSON 格式现在可用于上传/下载 React Intl 本地化文件。