0.2.0 • Published 1 year ago

3h-localizer v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

3h-localizer

A utility lib for localization in vue.

Example Usage

The following code creates a demo page containing a title and a select input, where the content of the title is controlled by selected language.

<template>
    <h1>{{ dict.HELLO_WORLD }}</h1>
    <select v-model="language">
        <option value="zh">中文</option>
        <option value="en">English</option>
    </select>
</template>

<script setup lang="ts">
import { Localizer, translationsToDicts, type Translations } from '3h-localizer';

type MyDict = {
    HELLO_WORLD: string;
};

type MyLanguages = 'zh' | 'en';

const translations: Translations<MyDict, MyLanguages> = {
    HELLO_WORLD: {
        zh: '你好,世界!',
        en: 'Hello, world!',
    },
};

const localizer = new Localizer<MyDict, MyLanguages>({
    defaultLanguage: 'en',
    dicts: translationsToDicts(translations),
});

const { language, dict } = localizer;
</script>

Links