vue-localer

Internationalization plugin for Vue.
1,158 2
Install
npm install vue-localer
Latest Version:1.5.3
Vue:3
License:MIT
Last Updated:Oct 25, 2024
Links: GitHub  ·  npm
Maintainer: shyam-chen

vue-localer

Internationalization plugin for Vue.

Install

$ npm i vue-localer
# or
$ yarn add vue-localer
# or
$ pnpm i vue-localer
# or
$ bun add vue-localer

Usage

First, prepare the multilingual files.

// src/locales/en-US.ts
export default {
  hello: `Hello, {msg}!`,
  world: `Hello, World!`,
};

// src/locales/ja-JP.ts
export default {
  hello: `こんにちは、{msg}!`,
  world: `こんにちは、世界!`,
};

// src/locales/ko-KR.ts
export default {
  hello: `안녕하세요, {msg}!`,
  world: `안녕하세요, 월드!`,
};

Instantiate vue-localer and load multiple language files.

// src/plugins/localer.ts
import { createLocaler } from 'vue-localer';

import enUS from '~/locales/en-US';

export default createLocaler({
  fallbackLocale: 'en-US',
  messages: {
    'en-US': enUS,
    'ja-JP': () => import('~/locales/ja-JP'),
    'ko-KR': () => import('~/locales/ko-KR'),
  },
});

Register the instantiated vue-localer as app-level functionality to Vue.

// src/main.ts
import { createApp } from 'vue';

import localer from '~/plugins/localer';

import App from './App.vue';

const app = createApp(App);

app.use(localer);

app.mount('#root');

Next, by using useLocale, you can obtain the source of the current locale.

<script lang="ts" setup>
import { useLocaler, useLocale } from 'vue-localer';

const { f } = useLocaler();
const locale = useLocale();
</script>

<template>
  <div>{{ f(locale.hello, { msg: 'Vue' }) }}</div>
  <div>{{ locale.world }}</div>
</template>

Documentation

To learn more about vue-localer, check its documentation.

Related Packages

@tolgee/vue

Vue implementation for Tolgee localization framework

410,505 261
vue3-gettext

Translate Vue 3 applications with gettext

865,515 86
@generaltranslation/vue-extractor

Vue source code extraction for General Translation

410,565 1,070
@byjohann/vue-i18n

Lightweight internationalization plugin for Vue

8,721 7
@rareformlabs/vue3-gettext

Translate Vue 3 applications with gettext (maintained fork)

7,088 1

Version History

Version Released Vue License
1.5.3 ^3.4.27 MIT
1.5.2 ^3.4.27 MIT
1.5.1 ^3.4.27 MIT
1.5.0 ^3.4.27 MIT
1.4.1 ^3.4.21 MIT