Skip to main content

国际化(i18n)

¥Internationalization (i18n)

国际化功能允许管理不同语言的内容,称为 "locales"。

¥The Internationalization feature allows to manage content in different languages, called "locales".

功能的身份证

计划:免费功能。
角色和权限:无。
激活:可用但默认禁用。
环境:在开发和生产环境中均可用。

¥ Plan: Free feature.
Role & permission: None.
Activation: Available but disabled by default.
Environment: Available in both Development & Production environment.

i18n settingsi18n settings

配置

¥Configuration

在内容管理器中可用之前,必须从 设置中配置国际化功能,并且应从 内容类型构建器在你的内容类型上启用它。

¥Before being usable in the Content Manager, the Internationalization feature must be configured from Settings, and it should be enabled on your content types from the Content-type Builder.

内容类型生成器

¥Content-type Builder

配置功能的路径: 内容类型生成器

¥Path to configure the feature: Content-type Builder

为了使你的内容类型能够在内容管理器中使用国际化进行翻译,必须通过内容类型构建器启用该功能。可以为每种内容类型和/或字段配置国际化。

¥For your content types to be translatable with Internationalization in the Content Manager, the feature must be enabled through the Content-type Builder. Internationalization can be configured for each content type and/or field.

  1. 编辑所选已创建的内容类型/字段,或创建新的内容类型/字段。

    ¥Either edit the already created content type/field of your choice, or create a new content type/field.

  2. 转到高级设置选项卡。

    ¥Go to the Advanced settings tab.

  3. 在内容类型级别勾选名为 "国际化" 的选项,在字段级别勾选名为 "启用该字段的本地化" 的选项。

    ¥Tick the option named "Internationalization" at content-type level, and "Enable localization for this field" at field level.

Content-type Builder's advanced settingsContent-type Builder's advanced settings

设置

¥Settings

配置功能的路径: 设置 > 全局设置 > 国际化

¥Path to configure the feature: Settings > Global Settings > Internationalization

国际化界面显示一个表格,列出了 Strapi 应用可用的所有语言环境。默认情况下,仅配置英语区域设置并将其设置为默认区域设置。

¥The Internationalization interface displays a table listing all locales available for the Strapi application. By default, only the English locale is configured and set as the default locale.

对于每个区域设置,该表显示该区域设置的默认 ISO 代码、其可选显示名称,并指示该区域设置是否设置为默认区域设置。从该表中,管理员还可以:

¥For each locale, the table displays the default ISO code of the locale, its optional display name and indicates if the locale is set as the default one. From the table, administrators can also:

  • 点击编辑按钮 编辑语言环境

    ¥Click on the edit button to edit a locale

  • 单击删除按钮 删除语言环境

    ¥Click on the delete button to delete a locale

添加新区域设置

¥Adding a new locale

管理员可以根据需要添加和管理任意数量的区域设置。然而,只能将一种区域设置设置为整个 Strapi 应用的默认区域设置。

¥Administrators can add and manage as many locales as they want. There can however only be one locale set as the default one for the whole Strapi application.

注意

无法创建自定义区域设置。只能根据 Strapi 设置的 500 多个预先创建的语言环境列表  创建语言环境。

¥It is not possible to create custom locales. Locales can only be created based on the 500+ pre-created list of locales  set by Strapi.

  1. 单击添加新区域设置按钮。

    ¥Click on the Add new locale button.

  2. 在区域设置添加窗口中,从区域设置下拉列表中选择新的区域设置。后者按字母顺序列出了所有可以添加到你的 Strapi 应用中的区域设置,并显示为其 ISO 代码。

    ¥In the locale addition window, choose your new locale among the Locales drop-down list. The latter lists alphabetically all locales, displayed as their ISO code, that can be added to your Strapi application.

  3. (可选)在区域设置显示名称文本框中,为新区域设置写入新的显示名称。

    ¥(optional) In the Locale display name textbox, write a new display name for your new locale.

  4. (可选)在“高级设置”选项卡中,勾选“设为默认区域设置”设置,使你的新区域设置成为 Strapi 应用的默认区域设置。

    ¥(optional) In the Advanced settings tab, tick the Set as default locale setting to make your new locale the default one for your Strapi application.

  5. 单击“保存”按钮确认添加新区域设置。

    ¥Click on the Save button to confirm the addition of your new locale.

Adding new locale with i18nAdding new locale with i18n

基于代码的配置

¥Code-based configuration

可以配置 STRAPI_PLUGIN_I18N_INIT_LOCALE_CODE 环境变量 来设置你的环境的默认区域设置。此变量使用的值应为来自 500 多个预先创建的语言环境列表  的 ISO 国家代码。

¥A STRAPI_PLUGIN_I18N_INIT_LOCALE_CODE environment variable can be configured to set the default locale for your environment. The value used for this variable should be an ISO country code from the 500+ pre-created list of locales .

用法

¥Usage

使用功能的路径: 内容管理器,内容类型的编辑视图

¥Path to use the feature: Content Manager, edit view of your content type

内容管理者 中,当为内容类型启用国际化功能时,编辑视图的右上角会添加一个语言环境下拉列表,并允许切换语言环境。

¥In the Content Manager, when the Internationalization feature is enabled for the content-type, a locale drop-down list is added to the top right of the edit view and allows to switch locales.

国际化功能还允许动态区域和组件在不同语言环境中有所不同。根据区域设置,动态区域确实可以根据区域设置具有不同的结构,并且可重复组件可以具有不同的条目并且也可以以不同的方式组织。

¥The Internationalization feature also allows dynamic zones and components to differ from one locale to another. Depending on the locale, dynamic zones can indeed have different structures depending on the locale, and repeatable components can have different entries and be organized differently as well.

提醒

内容一次只能在一种区域设置下进行管理。无法同时编辑或发布多个区域设置的内容(例如,单击“发布”按钮将仅发布你当前正在处理的区域设置的内容)。

¥Content can only be managed one locale at the time. It is not possible to edit or publish content for several locales at the same time (e.g. Clicking on the Publish button will only publish the content for the locale you are currently working on).

要翻译其他语言环境中的内容:

¥To translate content in another locale:

  1. 在编辑视图的右上角,单击语言环境下拉列表。

    ¥On the top right of the edit view, click on the locale drop-down list.

  2. 选择你想要翻译内容的区域设置。

    ¥Choose the locale in which you want to translate your content.

  3. 通过填写内容类型的字段来翻译你的内容。

    ¥Translate your content by filling up your content-type's fields.

提示

单击右上角的 从另一个语言环境填写按钮,所有非关系字段都将用另一个所选语言环境的值填充。如果你不记得另一个语言环境中的确切内容是什么,它可能会很有用。

¥Click on the Fill in from another locale button, in the top right corner, for all non relational fields to be filled up with the values of another chosen locale. It can be useful if you do not remember what was the exact content in another locale.

Managing locales with i18nManaging locales with i18n

使用 API

¥Usage with APIs

可以通过 Strapi 的内容 API 访问的各种前端 API 为给定语言环境请求、创建、更新和删除本地化内容:

¥Localized content can be requested, created, updated, and deleted for a given locale through the various front-end APIs accessible from Strapi's Content API:

在 Strapi 的后端服务器上,文档服务 API 还可用于与本地化内容进行交互:

¥On the back-end server of Strapi, the Document Service API can also be used to interact with localized content: