i18n
设置支持的语言
import { defineSiteConfig } from 'valaxy'
export default defineSiteConfig({
languages: ['zh-CN', 'en'],
})在配置中使用国际化
如果你想要为 siteConfig.title/siteConfig.description 添加国际化支持,可以在 siteConfig 中设定键值。
TIP
$t 是 Valaxy 提供的一个虚拟函数,它会添加特定的前缀 $locale: 以标记此处的文本需要国际化处理。 随后,Valaxy 会在页面中自动替换为对应语言的文本。 因此,它在页面上仍然是支持响应式的。
例如:
import { $t, defineSiteConfig } from 'valaxy'
export default defineSiteConfig({
title: $t('siteConfig.title'),
description: $t('siteConfig.description'),
})然后在 locales 目录下创建对应的语言文件。
siteConfig:
title: 你好,世界siteConfig:
title: Hello Worldi18n in One Page
TIP
Valaxy proposed a CSS-based i18n solution for blog.
You can quickly write English and Chinese blogs from the same page.
If you want to know how this works, see i18n.
The effect is as follows (click the button to switch).
Another i18n method.
More info…
English
Written like this:
Another i18n method.
More info...
EnglishTitle i18n
Of course, Valaxy supports i18n on titles. Works the same as above.
You can write internationalized titles like this:
### Hello WorldFrontmatter i18n
Internationalizing title and description:
---
title:
en: Hello World
zh-CN: 你好,世界
description:
en: A simple i18n example
zh-CN: 一个简单的 i18n 示例
---Category/Tag i18n
TIP
为什么这里不是使用类似 title/description 的对象方式,而是使用特殊前缀 $locale:tag.notes 的方式?
因为分类和标签仍然需要一个唯一的键值,且它们通常是在多篇文章中复用的。 如果使用对象方式,你将不得不在每篇文章的 frontmatter 中重复定义分类和标签的多种语言。
---
categories:
- $locale:category.test
tags:
- $locale:tag.notes
---category:
test: 测试
tag:
notes: 笔记category:
test: Test
tag:
notes: Notes