Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

laravel-vue-i18n

> 前端框架
Open source

Allows to connect your `Laravel` Framework translation files with `Vue`.

710 stars0 likes1 views
WebsiteGitHub

About

Allows to connect your `Laravel` Framework translation files with `Vue`.

Laravel Vue i18n

laravel-vue-i18n is a Vue3 plugin that allows to connect your Laravel Framework translation
files with Vue. It uses the same logic used on Laravel Localization.

Installation

With npm:

bash
npm i laravel-vue-i18n

or with yarn:

bash
yarn add laravel-vue-i18n

Setup

If you want to see a screencast on how to setup check out this video: How to use Laravel Vue i18n plugin.

With Vite

javascript
import { createApp } from 'vue'
import { i18nVue } from 'laravel-vue-i18n'

createApp()
    .use(i18nVue, {
        resolve: async lang => {
            const langs = import.meta.glob('../../lang/*.json');
            return await langs[`../../lang/${lang}.json`]();
        }
    })
    .mount('#app');

SSR (Server Side Rendering)

For Server Side Rendering the resolve method should not receive a Promise and instead take advantage of the eager param like this:

javascript
.use(i18nVue, {
    lang: 'pt',
    resolve: lang => {
        const langs = import.meta.glob('../../lang/*.json', { eager: true });
        return langs[`../../lang/${lang}.json`].default;
    },
})

PHP Translations Available on Vue

In order to load php translations, you can use this Vite plugin.

…

bash lang/php_*.json

bash

#### With Vite+

Follow the [Vite+ migration guide](https://viteplus.dev/guide/migrate) to install Vite+ and configure its Vite dependency alias. Then use the existing plugin in your config:

```js
import { defineConfig } from 'vite-plus';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';
import i18n from 'laravel-vue-i18n/vite';

export default defineConfig({
    plugins: [
        laravel({ input: ['resources/js/app.js'] }),
        vue(),
        i18n(),
    ],
});

Run vp dev or vp build. The Vue setup and translation resolver shown above stay the same. Vite+ is optional; this package does not install it.

With Webpack / Laravel Mix

javascript
import { createApp } from 'vue'
import { i18nVue } from 'laravel-vue-i18n'

createApp()
    .use(i18nVue, {
        resolve: lang => import(`../../lang/${lang}.json`),
    })
    .mount('#app');

SSR (Server Side Rendering)

For Server Side Rendering the resolve method should receive a require instead of a Promise:

javascript
.use(i18nVue, {
    lang: 'pt',
    resolve: lang => require(`../../lang/${lang}.json`),
})

PHP Translations Available on Vue

In order to load php translations, you can use this Mix plugin.

javascript
const mix = require('laravel-mix');
require('laravel-vue-i18n/mix');

// Laravel >= 9
mix.i18n();

// Laravel 
    

    

…

js
createApp().use(i18nVue, {
    lang: 'pt',
    resolve: lang => import(`../../lang/${lang}.json`),
})

trans(message: string, replacements: {})

The trans() method can translate a given message.

javascript
// lang/pt.json
{
    "Welcome!": "Bem-vindo!",
    "Welcome, :name!": "Bem-vindo, :name!"
}

import { trans } from 'laravel-vue-i18n';

trans('Welcome!'); // Bem-vindo!
trans('Welcome, :name!', { name: 'Francisco' }) // Bem-vindo Francisco!
trans('Welcome, :NAME!', { name: 'Francisco' }) // Bem-vindo FRANCISCO!

wTrans(message: string, replacements: {})

The wTrans() same as trans() but returns a reactive obj with translated value, use it instead of trans() to watch any changes (language changes or lang files loaded) and set the new value.

javascript
// lang/pt.json
{
    "Welcome!": "Bem-vindo!",
    "Welcome, :name!": "Bem-vindo, :name!"
}

import { wTrans } from 'laravel-vue-i18n';

setup() {
    return {
        welcomeLabel: wTrans('Welcome!'),
        welcomeFrancisco: wTrans('Welcome, :name!', { name: 'Francisco' })
    }
}

    
 // 

    
 // 

transChoice(message: string, count: number, replacements: {})

The transChoice() method can translate a given message based on a count, there is also available an trans_choice alias, and a mixin called $tChoice().

javascript
// lang/pt.json
{
    "There is one apple|There are many apples": "Existe uma maça|Existe muitas maças",
    "{0} There are none|[1,19] There are some|[20,*] There are many": "Não tem|Tem algumas|Tem muitas",
    "{1} :count minute ago|[2,*] :count minutes ago": "{1} há :count minuto|[2,*] há :count minutos"
}

import { transChoice } from 'laravel-vue-i18n';

transChoice('There is one apple|There are many apples', 1); // Existe uma maça
transChoice('{0} There are none|[1,19] There are some|[20,*] There are many', 19); // Tem algumas
transChoice('{1} :count minute ago|[2,*] :count minutes ago', 10); // Há 10 minutos.

wTransChoice(message: string, count: number, replacements: {})

The wTransChoice() same as transChoice() but returns a reactive obj with translated value, use it instead of transChoice() to watch any changes (language changes or lang files loaded) and set the new value.

javascript
// lang/pt.json
{
    "There is one apple|There are many apples": "Existe uma maça|Existe muitas maças",
    "{0} There are none|[1,19] There are some|[20,*] There are many": "Não tem|Tem algumas|Tem muitas",
    "{1} :count minute ago|[2,*] :count minutes ago": "{1} há :count minuto|[2,*] há :count minutos"
}

import { wTransChoice } from 'laravel-vue-i18n';

setup() {
    return {
        oneAppleLabel: wTransChoice('There is one apple|There are many apples', 1),
        multipleApplesLabel: wTransChoice('{0} There are none|[1,19] There are some|[20,*] There are many', 19)
    }
}

    
 // 

    
 // 

loadLanguageAsync(lang: string)

The loadLanguageAsync() can be used to change the location during the runtime.

javascript
import { loadLanguageAsync } from 'laravel-vue-i18n';

    

    Change to Portuguese Language

getActiveLanguage()

The getActiveLanguage() returns the language that is currently being used.

javascript
import { getActiveLanguage } from 'laravel-vue-i18n';

const lang = getActiveLanguage(); // en

isLoaded(lang?: string)

The isLoaded() method checks if the language is loaded. If the lang parameter is not passed it will check for the actual language set.

javascript
import { isLoaded } from 'laravel-vue-i18n';

const loaded = isLoaded(); // true
const loaded = isLoaded('fr'); // false

…

js
import { I18n } from 'laravel-vue-i18n'

const resolver = lang => import(`./fixtures/lang/${lang}.json`)

const i18nEn = new I18n({
    lang: 'en',
    resolve: resolver
})
const i18nPt = new I18n({
    lang: 'pt',
    resolve: resolver
})

i18nEn.trans('Welcome!') // will output "Welcome!"
i18nPt.trans('Welcome!') // will output "Bem-vindo!"

By default, installing the the i18nVue plugin will create a shared instance. This instance is accessed when importing the translation functions, such as trans, directly. When using multiple Vue app instances, it's possible to either share the I18n instance between them, or have each app create its own instance.

Shared usage (default) - all Vue app instances will use the same I18n class and currently active language:

javascript
import { i18nVue } from 'laravel-vue-i18n'

const appA = createApp()
    .use(i18nVue, { lang: 'pt' })
    .mount('#app-1');

const appB = createApp()
    .use(i18nVue)
    .mount('#app-2');

// elsewhere
import { trans } from 'laravel-vue-i18n'

trans('Welcome!') // will output "Bem-vindo!"

Non-shared usage - each Vue app will have its own I18n instance & currently active language.

javascript
import { i18nVue } from 'laravel-vue-i18n'

const appA = createApp()
    .use(i18nVue, {
        lang: 'es'
        shared: false, // don't use the shared instance
    })
    .mount('#app-1');

const appB = createApp()
    .use(i18nVue, {
        lang: 'pt'
        shared: false, // don't use the shared instance
    })
    .mount('#app-2');

Accessing the shared instance

It's possible to access the shared instance via code as well:

javascript
import { I18n } from 'laravel-vue-i18n'

I18n.getSharedInstance()

…

bash
sh
npm ci
npm test
npm run typecheck
npm run test:types
npm run lint
npm run test:integration

npm run build uses tsdown to produce the existing ESM and CommonJS entry points, with declarations for NodeNext, bundler, and legacy TypeScript resolution. npm run watch rebuilds those outputs during development. Vitest runs the unit and Vite lifecycle tests.

The integration command packs the library and installs it into temporary consumer projects for Vite 4–8, Vite+, and Mix. It checks translation rendering in jsdom, SSR, package imports, types, file watching, and cleanup. To select a consumer, use npm run test:integration -- 8, -- plus, or -- mix. These checks install dependencies and require network access.

Webpack is deliberately kept at ~5.99.9 in the development dependencies to retain the Mix 6 compatibility check. TypeScript uses the latest 5.9 patch line; consumer declarations also retain the legacy paths supported by 2.x.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptjavascriptlaravellaravel-frameworktypescript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架