docs: add how to use i18n in config or page

This commit is contained in:
YunYouJun 2025-07-12 19:33:06 +08:00
parent e537ac80b5
commit cafa1e3e27
2 changed files with 57 additions and 10 deletions

View File

@ -1,11 +1,42 @@
---
title:
en: i18n in One Page
zh-CN: 单页 i18n
en: i18n
zh-CN: 国际化
categories:
- guide
---
## 在配置中使用国际化
如果你想要为 `siteConfig.title`/`siteConfig.description` 添加国际化支持,可以在 `siteConfig` 中设定键值。
例如:
```ts [site.config.ts]
import { defineSiteConfig } from 'valaxy'
export default defineSiteConfig({
title: 'siteConfig.title',
description: 'siteConfig.description',
})
```
然后在 `locales` 目录下创建对应的语言文件。
```yaml [locales/zh-CN.yml]
siteConfig:
title: 你好,世界
```
```yaml [locales/en.yml]
siteConfig:
title: Hello World
```
## 单页 i18n {lang="zh-CN"}
## i18n in One Page {lang="en"}
::: tip
<div lang="zh-CN">
@ -92,9 +123,9 @@ English
:::
```
## 标题 i18n {lang="zh-CN"}
### 标题 i18n {lang="zh-CN"}
## Title i18n {lang="en"}
### Title i18n {lang="en"}
::: zh-CN
当然Valaxy 同样支持标题的 i18n。原理同上。
@ -108,12 +139,29 @@ Of course, Valaxy supports i18n on titles. Works the same as above.
You can write internationalized titles like this:
:::
### 你好,世界 {lang="zh-CN"}
### Hello World {lang="en"}
```md
### 你好,世界 {lang="zh-CN"}
### Hello World {lang="en"}
```
### Frontmatter i18n
::: zh-CN
实现 `title``description` 的国际化:
:::
::: en
Internationalizing `title` and `description`:
:::
```md
---
title:
en: Hello World
zh-CN: 你好,世界
description:
en: A simple i18n example
zh-CN: 一个简单的 i18n 示例
---
```

View File

@ -8,8 +8,7 @@ export function useEditLink() {
return computed(() => {
const { text, pattern } = themeConfig.value.editLink || {}
const url = pattern.replace(/:path/g, page.value.relativePath)
const url = pattern.replace(/:path/g, page.value?.relativePath || '')
return { url, text }
})
}