Skip to main content

国际化 (i18n)

🌐 Internationalization (i18n)

Page summary:

国际化可以直接从管理面板管理多个地区的内容。本指南解释了如何添加地区、翻译条目以及控制特定地区的权限。

国际化功能允许管理不同语言的内容,称为“本地化”。

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

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

配置

🌐 Configuration

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

内容类型构建器

🌐 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. 编辑所选已创建的内容类型/字段,或创建新的内容类型/字段。
  2. 转到高级设置选项卡。
  3. 在内容类型级别勾选名为“国际化”的选项,在字段级别勾选“启用此字段的本地化”。
Content-type Builder's advanced settingsContent-type Builder's advanced settings

设置

🌐 Settings

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

国际化 界面显示一个表格,列出 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:

  • 点击编辑按钮 以编辑本地化
  • 点击删除按钮 以删除一个语言环境

添加新语言环境

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

Note

无法创建自定义语言环境。语言环境只能基于 Strapi 设置的 the 500+ pre-created list of locales 创建。

  1. 点击添加新语言环境按钮。
  2. 在语言环境添加窗口中,从“语言环境”下拉列表中选择你的新语言环境。后者按字母顺序列出所有可以添加到你的 Strapi 应用的语言环境,并显示其 ISO 代码。
  3. (可选) 在 Locale display name 文本框中,为你的新语言环境输入一个新的显示名称。
  4. (可选)在“高级设置”选项卡中,勾选设置为默认语言环境选项,以将你的新语言环境设置为 Strapi 应用的默认语言环境。
  5. 点击 保存 按钮以确认添加你的新语言环境。
Adding new locale with i18nAdding new locale with i18n

启用人工智能驱动的国际化

🌐 Enabling AI-powered internationalization

GrowthThis feature is available with a Growth plan.

AI驱动的国际化在默认语言内容更新时,可为项目中的所有地区自动进行翻译。这使内容编辑可以在几秒钟内将其内容翻译成多种语言。

🌐 AI-Powered Internationalization enables automatic translations for all the locales in a project when the content in the default locale is updated. This enables content editors to have their content translated into multiple languages within a few seconds.

AI 驱动的国际化默认是禁用的。要启用它,请转到 设置 > 全局设置 > 国际化 并将 AI 翻译 设置为 启用

Internationalization settingsInternationalization settings

基于代码的配置

🌐 Code-based configuration

可以配置一个 STRAPI_PLUGIN_I18N_INIT_LOCALE_CODE 环境变量 来设置环境的默认语言环境。此变量使用的值应为来自 the 500+ pre-created list of locales的 ISO 国家代码。

使用

🌐 Usage

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

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

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

Info

在不同内容类型之间导航时,所选的本地设置会保持不变。例如,如果在编辑某个内容类型时选择了西班牙语本地设置,切换到另一个内容类型时,西班牙语本地设置仍会被选中,即使该内容类型未启用国际化。这使得在整个内容中使用特定本地设置工作更加方便。

🌐 The selected locale persists when navigating between content types. For instance, if you select the Spanish locale while editing a content-type, switching to another content type will keep the Spanish locale selected, even if that content type does not have Internationalization enabled. This makes it easier to work in a specific locale across your content.

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

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

Caution

内容一次只能管理一个语言区域。无法同时编辑或发布多个语言区域的内容(例如,点击发布按钮只会发布你当前正在处理的语言区域的内容)。

🌐 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. 在编辑视图的右上角,单击语言环境下拉列表。
  2. 选择你想要翻译内容的区域设置。
  3. 通过填写内容类型的字段来翻译你的内容。
Managing locales with i18nManaging locales with i18n
Tip

点击右上角的 从其他语言环境填充按钮,所有非关联字段将使用所选语言环境的值进行填充。如果你不记得其他语言环境中的确切内容,这将非常有用。如果你已启用AI 驱动的国际化,此按钮将不可见,因为翻译会由 Strapi AI 自动处理。

人工智能驱动的国际化 NewThis content is new.

🌐 AI-powered internationalization NewThis content is new.

GrowthThis feature is available with a Growth plan.

启用时,AI驱动的国际化可以在源内容更新时为项目中的所有区域自动进行翻译。这使内容编辑者能够在几秒钟内将其内容翻译成多种语言。该功能的理念是确保用户只在默认区域手动填写内容,而 Strapi AI 会为所有其他现有区域进行翻译。

一旦启用,每当你在默认语言环境中编辑内容类型并点击 保存 时,该内容类型的所有其他语言环境将自动补齐翻译,系统会通过 所有语言环境已翻译 的通知进行确认。使用此功能将消耗 Strapi AI 积分。

🌐 Once enabled, whenever you edit a content-type in the default locale and click Save, all other locales for the content-type should be translated automatically, which will be confirmed by an All locales have been translated notification. Using this feature consumes Strapi AI credits.

Managing locales with AI-powered i18nManaging locales with AI-powered i18n
Caution

由人工智能驱动的国际化只以一种方式工作,将默认语言内容保持为唯一的真实来源。因此,一旦启用该功能:

🌐 AI-powered internationalization only works one way, keeping the default locale content as the unique source of truth. Consequently, once the feature is enabled:

  • 编辑和保存除默认语言之外的任何语言的内容都不会触发自动翻译。
  • 编辑默认语言环境的内容时,对其他语言环境所做的手动修改将被覆盖。
Strapi AI credits

Strapi AI 在 Growth 计划中每月包含 1,000 个积分,并且在免费试用期间提供 10 个免费积分。轻量级操作使用较少积分,而更复杂的操作使用更多积分。

你可以在管理面板的 Settings Overview 中查看你的信用使用情况。当你的使用量达到月度配额的80%、90%和100%时,将会发送通知。

当你的 Growth 套餐积分用完后,你可以继续使用 Strapi AI,超出部分将按月计费。

有关 Strapi AI 的更多信息,请参阅专门的支持文章

🌐 For more information about Strapi AI, please refer to the dedicated support article.

与 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: