Skip to content

vui18n is internationalization module. It easily integrates some localization features to your Vue.js Application.

Notifications You must be signed in to change notification settings

ilijanovic/vui18n

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vui18n

vui18n is internationalization module. It easily integrates some localization features to your Vue.js Application.

Installation

You can install it with npm

npm i vui18n

Only for Vue.js 3

Get started

To get started, you need to initialize the module. You can do it inside main.ts file:

import { createApp, ref } from "vue";
import { initLanguage } from "vui18n";
import App from "./App.vue";
initLanguage(
  {
    languages: [
      {
        code: "en",
        path: "/languages/en.json",
      },
      {
        code: "de",
        path: "/languages/de.json",
      },
    ],
  },
  ref
);
const app = createApp(App);
app.mount("#app");

Its important to pass ref as the second argument to the initLanguage function. This is your starting point. The translation files are lazy loaded by default. This means only the translation file that is being used is loaded.

Use it in your app

<script setup lang="ts">
import { t } from "vui18n"
</script>
<template>
    <div>
        <p>{{ t("name") }}</p>
    </div>
</template>

The text will no be translated. The default language is en

Switch languages

You can switch the languages:

<script setup lang="ts">
  import {switchLang} from "vui18n" 
  switchLang("de")
</script>

You need to pass the locale code. switchLang returns an promise. It lazy load the translation file.

Get selected language

You can get the current language with getSelectedLanguage

<script setup lang="ts">
  import {getSelectedLanguage} from "vui18n"
</script>

Get all languages

You can access all languages with getLanguages

<script setup lang="ts">
  import {getLanguages} from "vui18n"
</script>

About

vui18n is internationalization module. It easily integrates some localization features to your Vue.js Application.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published