3h-localizer
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

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

Package Sidebar

Install

npm i 3h-localizer

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

14.3 kB

Total Files

11

Last publish

Collaborators

  • 3h