From 87f0d5cc8b8016a87931c26b059d995fc178c624 Mon Sep 17 00:00:00 2001 From: liruifengv Date: Wed, 8 Jan 2025 17:21:47 +0800 Subject: i18n(zh-cn): Update i18n.mdx (#2775) Co-authored-by: HiDeoo <494699+HiDeoo@users.noreply.github.com>--- docs/src/content/docs/zh-cn/guides/i18n.mdx | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/docs/src/content/docs/zh-cn/guides/i18n.mdx b/docs/src/content/docs/zh-cn/guides/i18n.mdx index ada24a27..00fd8fb6 100644 --- a/docs/src/content/docs/zh-cn/guides/i18n.mdx +++ b/docs/src/content/docs/zh-cn/guides/i18n.mdx @@ -187,16 +187,17 @@ import UIStringsList from '~/components/ui-strings-list.astro'; -1. 如果尚未配置,请在 `src/content/config.ts` 中配置 `i18n` 数据集合: +1. 如果尚未配置,请在 `src/content.config.ts` 中配置 `i18n` 数据集合: - ```diff lang="js" ins=/, (i18nSchema)/ - // src/content/config.ts + ```diff lang="js" ins=/, (i18nLoader|i18nSchema)/ + // src/content.config.ts import { defineCollection } from 'astro:content'; + import { docsLoader, i18nLoader } from '@astrojs/starlight/loaders'; import { docsSchema, i18nSchema } from '@astrojs/starlight/schema'; export const collections = { - docs: defineCollection({ schema: docsSchema() }), - + i18n: defineCollection({ type: 'data', schema: i18nSchema() }), + docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }), + + i18n: defineCollection({ loader: i18nLoader(), schema: i18nSchema() }), }; ``` @@ -256,14 +257,15 @@ import UIStringsList from '~/components/ui-strings-list.astro'; 在下面的示例中添加了一个新的可选的 `custom.label` 键: ```diff lang="js" -// src/content/config.ts +// src/content.config.ts import { defineCollection, z } from 'astro:content'; +import { docsLoader, i18nLoader } from '@astrojs/starlight/loaders'; import { docsSchema, i18nSchema } from '@astrojs/starlight/schema'; export const collections = { - docs: defineCollection({ schema: docsSchema() }), + docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }), i18n: defineCollection({ - type: 'data', + loader: i18nLoader(), schema: i18nSchema({ + extend: z.object({ + 'custom.label': z.string().optional(), @@ -273,14 +275,14 @@ export const collections = { }; ``` -在 Astro 文档的[“定义集合模式”](https://docs.astro.build/zh-cn/guides/content-collections/#定义集合模式)中了解有关内容集合 schema 的更多信息。 +在 Astro 文档的[“定义集合模式”](https://docs.astro.build/zh-cn/guides/content-collections/#定义集合模式schema)中了解有关内容集合 schema 的更多信息。 ## 使用 UI 翻译 你可以使用由 [i18next](https://www.i18next.com/) 提供支持的统一 API 访问 Starlight 的 [内置 UI 字符串](/zh-cn/guides/i18n/#翻译-starlight-的-ui) 以及 [用户定义](/zh-cn/guides/i18n/#拓展翻译-schema) 和 [插件提供](/zh-cn/reference/plugins/#injecttranslations) 的 UI 字符串。 其中包括了对 [插值](https://www.i18next.com/translation-function/interpolation) 和 [多元化](https://www.i18next.com/translation-function/plurals) 等功能的支持。 -在 Astro 组件中,此 API 作为 [全局 `Astro` 对象](https://docs.astro.build/zh-cn/reference/api-reference/#astrolocals) 的一部分提供,即 `Astro.locals.t`: +在 Astro 组件中,此 API 作为 [全局 `Astro` 对象](https://docs.astro.build/zh-cn/reference/api-reference/#locals) 的一部分提供,即 `Astro.locals.t`: ```astro title="example.astro"

@@ -288,7 +290,7 @@ export const collections = {

``` -你还可以在 [端点](https://docs.astro.build/zh-cn/guides/endpoints/) 中使用 API,其中的 `locals` 对象可作为 [端点上下文](https://docs.astro.build/zh-cn/reference/api-reference/#contextlocals) 的一部分使用: +你还可以在 [端点](https://docs.astro.build/zh-cn/guides/endpoints/) 中使用 API,其中的 `locals` 对象可作为 [端点上下文](https://docs.astro.build/zh-cn/reference/api-reference/#locals) 的一部分使用: ```ts title="src/pages/404.ts" export const GET = (context) => { @@ -389,7 +391,7 @@ const arabicDirection = Astro.locals.t.dir('ar'); ## 访问当前语言环境 -你可以使用 [`Astro.currentLocale`](https://docs.astro.build/zh-cn/reference/api-reference/#astrocurrentlocale) 在 `.astro` 组件中读取当前的语言环境。 +你可以使用 [`Astro.currentLocale`](https://docs.astro.build/zh-cn/reference/api-reference/#currentlocale) 在 `.astro` 组件中读取当前的语言环境。 下面的示例读取当前语言环境,并使用它和 [`getRelativeLocaleUrl()`](https://docs.astro.build/zh-cn/reference/modules/astro-i18n/#getrelativelocaleurl) 助手函数以生成一个当前语言的关于页面的链接: -- cgit