Skip to main content

本地化与翻译

🌐 Locales & translations

Page summary:

通过更新 config.locales 数组来配置管理面板语言,并使用 config.translations 或自定义翻译文件覆盖默认或插件字符串。

Strapi 管理面板 默认提供英文字符串,并支持添加其他语言环境,以便你的编辑团队可以使用他们偏好的语言进行工作。语言环境决定界面中显示的语言,而翻译则提供在某个语言环境中每个键显示的文本。

🌐 The Strapi admin panel ships with English strings and supports adding other locales so your editorial team can work in their preferred language. Locales determine which languages appear in the interface, while translations provide the text displayed for each key in a locale.

本指南面向从应用代码库自定义管理体验的项目维护者。所有示例都修改从 /src/admin/app 文件导出的配置,Strapi 在构建管理面板时会加载该配置。你将学习如何声明额外的语言环境,以及当语言环境缺少字符串时如何扩展 Strapi 或插件的翻译。

🌐 This guide targets project maintainers customizing the admin experience from the application codebase. All examples modify the configuration exported from /src/admin/app file, which Strapi loads when the admin panel builds. You'll learn how to declare additional locales and how to extend Strapi or plugin translations when a locale is missing strings.

定义区域设置

🌐 Defining locales

要在管理面板中更新可用语言环境列表,请在 src/admin/app 文件中设置 config.locales 数组:

🌐 To update the list of available locales in the admin panel, set the config.locales array in src/admin/app file:

/src/admin/app.js
export default {
config: {
locales: ["ru", "zh"],
},
bootstrap() {},
};
Notes
  • en 语言环境无法从构建中移除,因为它既是回退语言环境(即如果在某个语言环境中未找到翻译,将使用 en),也是默认语言环境(即当用户第一次打开管理面板时使用)。
  • 可用区域设置的完整列表可在 Strapi's Github repo上访问。

扩展翻译

🌐 Extending translations

翻译键/值对在 @strapi/admin/admin/src/translations/[language-name].json 文件中声明。

🌐 Translation key/value pairs are declared in @strapi/admin/admin/src/translations/[language-name].json files.

这些键可以通过 src/admin/app 文件中的 config.translations 键进行扩展:

🌐 These keys can be extended through the config.translations key in src/admin/app file:

/src/admin/app.js
export default {
config: {
locales: ["fr"],
translations: {
fr: {
"Auth.form.email.label": "test",
Users: "Utilisateurs",
City: "CITY (FRENCH)",
// Customize the label of the Content Manager table.
Id: "ID french",
},
},
},
bootstrap() {},
};

插件的键/值对在插件的文件 /admin/src/translations/[language-name].json 中独立声明。这些键/值对可以通过在 config.translations 键中添加前缀(插件的名称,即 [plugin name].[key]: 'value')来类似地扩展,如以下示例所示:

🌐 A plugin's key/value pairs are declared independently in the plugin's files at /admin/src/translations/[language-name].json. These key/value pairs can similarly be extended in the config.translations key by prefixing the key with the plugin's name (i.e. [plugin name].[key]: 'value') as in the following example:

/src/admin/app.js
export default {
config: {
locales: ["fr"],
translations: {
fr: {
"Auth.form.email.label": "test",
// Translate a plugin's key/value pair by adding the plugin's name as a prefix
// In this case, we translate the "plugin.name" key of plugin "content-type-builder"
"content-type-builder.plugin.name": "Constructeur de Type-Contenu",
},
},
},
bootstrap() {},
};

如果你需要发送额外的翻译 JSON 文件——例如为了组织大型覆盖或支持 Strapi 未打包的本地化——请将它们放在 /src/admin/extensions/translations 文件夹中,并确保本地化代码已列在 config.locales 中。

🌐 If you need to ship additional translation JSON files—for example to organize large overrides or to support a locale not bundled with Strapi—place them in the /src/admin/extensions/translations folder and ensure the locale code is listed in config.locales.

Rebuild the admin

当管理员重建时,翻译更改会生效。如果更新未显示,请重新运行开发服务器或重建管理员以刷新打包的翻译。

🌐 Translation changes apply when the admin rebuilds. If updates don’t show, re-run your dev server or rebuild the admin to refresh bundled translations.