本地化
Editor 组件支持本地化功能,开发者可以以不同语言显示标签、消息和提示信息。该功能对于面向多语言用户群体的应用程序至关重要。本地化可通过为组件配置自定义翻译集来实现。
该库内置三种语言包:
- 中文
- 英文
- 德文
您也可以应用自定义语言包。
默认语言
默认应用英文语言包:
应用语言包
要应用内置语 言包,需从 "@svar-ui/vue-core" 导入 Locale 对象,从 "@svar-ui/core-locales" 导入核心语言包,从 "@svar-ui/editor-locales" 导入内置语言包,然后将所需语言的 words 属性添加到 Locale 标签中。
示例:
import { Locale } from "@svar-ui/vue-core";
import { cn } from "@svar-ui/editor-locales";
import { cn as cnCore } from "@svar-ui/core-locales";
<Locale :words="{ ...cn, ...cnCore }">
以下配置使 Editor 组件以德文显示文本。myLang 对象包含键值对,其中键为 Editor 默认使用的英文字符串,值为对应的德文翻译。Locale 组件包裹 Editor 并应用指定的翻译。
<script setup>
import { Locale } from "@svar-ui/vue-core";
import { Editor } from "@svar-ui/vue-editor";
const myLang = {
"This field is required": "Dieses Feld ist erforderlich",
"Invalid value": "Ungültiger Wert",
Yes: "Ja",
No: "Nein",
Save: "Speichern",
Cancel: "Abbrechen",
};
</script>
<template>
<Locale :words="{ editor: myLang }">
<Editor />
</Locale>
</template>
要应用自定义语言包,需要创建自定义语言包对象(或修改现有对象),并为所有 Editor 文本标签提供翻译(可以是任意所需语言)。您还需要添加来自 core 和 calendar 组件("@svar-ui/core-locales")的标签。详情请参阅 Core 本地化。
韩文示例:
const ko = {
editor: {
"Invalid value": "잘못된 값",
// other
},
core:{ ... },
calendar: { ... }
};
相关示例: Locales