Skip to main content

语言环境和翻译

¥Locales & translations

Page summary:

Configure the admin panel languages by updating the config.locales array and override default or plugin strings with config.translations or custom translation files.

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/appfile 导出的配置,Strapi 在管理面板构建时会加载该配置。你将学习如何声明其他语言环境,以及如何在语言环境缺少字符串时扩展 Strapi 或插件翻译。

¥This guide targets project maintainers customizing the admin experience from the application codebase. All examples modify the configuration exported from /src/admin/appfile, 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() {},
};
注意
  • en 语言环境无法从构建中删除,因为它既是后备语言环境(即,如果在语言环境中找不到翻译,则将使用 en)和默认语言环境(即,当用户第一次打开管理面板时使用) 时间)。

    ¥The en locale cannot be removed from the build as it is both the fallback (i.e. if a translation is not found in a locale, the en will be used) and the default locale (i.e. used when a user opens the administration panel for the first time).

  • 可用语言环境的完整列表可在 Strapi 的 Github 存储库 上访问。

    ¥The full list of available locales is accessible on 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.