文档服务 API:使用 locale 参数
🌐 Document Service API: Using the locale parameter
Page summary:文档服务 API 中的
locale参数允许你使用findOne()、findMany()、update()和delete()等方法查询、创建、更新、删除、发布和取消发布特定语言版本的文档。🌐 The
localeparameter in the Document Service API lets you query, create, update, delete, publish, and unpublish documents for specific language versions using methods likefindOne(),findMany(),update(), anddelete().
默认情况下,Document Service API 返回文档的默认语言版本(默认为'en',即英语版本,除非应用已设置了其他默认语言,详见国际化(i18n)功能)。本页面描述了如何使用 locale 参数仅获取或操作特定语言的数据。
🌐 By default the Document Service API returns the default locale version of documents (which is 'en', i.e. the English version, unless another default locale has been set for the application, see Internationalization (i18n) feature). This page describes how to use the locale parameter to get or manipulate data only for specific locales.
获取带有 findOne() 的本地化版本
🌐 Get a locale version with findOne()
strapi.documents().findOne()Get a locale version with findOne()
Pass a locale to findOne() to get the version of the document for that locale.
如果没有传递 status 参数,则默认返回 draft 版本。
🌐 If no status parameter is passed, the draft version is returned by default.
获取带有 findFirst() 的本地化版本
🌐 Get a locale version with findFirst()
strapi.documents().findFirst()Get a locale version with findFirst()
Pass a locale to findFirst() to return documents matching that locale.
如果没有传递 status 参数,则默认返回 draft 版本。
🌐 If no status parameter is passed, the draft version is returned by default.
使用 findMany() 获取本地化版本
🌐 Get locale versions with findMany()
如果没有传递 status 参数,则默认返回 draft 版本。
🌐 If no status parameter is passed, the draft versions are returned by default.
strapi.documents().findMany()Get locale versions with findMany()
Pass a locale to findMany() to return all documents that have this locale available.
解释:
给定以下 4 个具有不同语言环境的文档:
🌐 Given the following 4 documents that have various locales:
- 文件A:
- en
fr- it
- 文件 B:
- en
- it
- 文件 C:
fr
- 文件 D:
fr- it
findMany({ locale: 'fr' }) 只会返回那些有 'fr' 语言版本的文档的草稿版本,即文档 A、C 和 D。
create() 为一个区域创建文档
🌐 create() a document for a locale
strapi.documents().create()Create a document for a locale
Pass a locale to create() to create the document for that specific locale.
update() 本地化版本
🌐 update() a locale version
strapi.documents().update()Update a locale version
Pass a locale to update() to update only that specific locale version of a document.
delete() 语言区域版本
🌐 delete() locale versions
使用 Document Service API 的 delete() 方法 的 locale 参数仅删除某些语言版本。除非传入特定的 status 参数,否则这将删除草稿和已发布版本。
🌐 Use the locale parameter with the delete() method of the Document Service API to delete only some locales. Unless a specific status parameter is passed, this deletes both the draft and published versions.
删除一个语言版本
🌐 Delete a locale version
strapi.documents().delete()删除一个语言版本
Pass a locale to delete() to delete only that specific locale version of a document.
删除所有语言版本
🌐 Delete all locale versions
strapi.documents().delete()删除所有语言版本
Use the * wildcard with the locale parameter to delete all locale versions of a document.
publish() 语言版本
🌐 publish() locale versions
要使用文档服务 API 的 publish() 方法 仅发布文档的特定语言版本,请将 locale 作为参数传递:
🌐 To publish only specific locale versions of a document with the publish() method of the Document Service API, pass locale as a parameter: