文档服务 API:使用 locale
参数
¥Document Service API: Using the locale
parameter
默认情况下,文档服务 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()
如果传递了 locale
,则文档服务 API 的 findOne()
方法 将返回此语言环境的文档版本:
¥If a locale
is passed, the findOne()
method of the Document Service API returns the version of the document for this locale:
await strapi.documents('api::restaurant.restaurant').findOne({
documentId: 'a1b2c3d4e5f6g7h8i9j0klm',
locale: 'fr',
});
{
documentId: "a1b2c3d4e5f6g7h8i9j0klm",
name: "Biscotte Restaurant",
publishedAt: null, // draft version (default)
locale: "fr", // as asked from the parameters
// …
}
如果没有传递 status
参数,则默认返回 draft
版本。
¥If no status
parameter is passed, the draft
version is returned by default.