Skip to main content

语言环境和翻译

¥Locales & translations

Strapi 的 管理面板 始终附带英语翻译,但可以显示其他语言。你还可以覆盖界面中显示的任何文本。本页面展示了如何定义你自己的语言环境,以及如何从项目代码库扩展 Strapi 或插件翻译。

¥Strapi's admin panel always ships with English translations, but can display additional languages. You can also override any text that appears in the interface. The present page shows how to define your own locales and extend Strapi or plugin translations from the project codebase.

定义语言环境

¥Defining locales

要更新管理面板中的可用区域设置列表,请使用 config.locales 数组:

¥To update the list of available locales in the admin panel, use the config.locales array:

/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.

这些键可以通过 config.translations 键扩展:

¥These keys can be extended through the config.translations key:

/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() {},
};

如果需要添加更多翻译文件,请将它们放在 /src/admin/extensions/translations 文件夹中。

¥If more translations files should be added, place them in the /src/admin/extensions/translations folder.