Skip to content

Generates a vue-i18n compatible include file from your Laravel translations

Notifications You must be signed in to change notification settings

alekslyse/laravel-vue-i18n-generator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

Build Status

Laravel 5 package that allows you to share your Laravel localizations with your vue front-end, using vue-i18n.

Usage

In your project: composer require andre-dw/laravel-vue-i18n-generator

In config/app.php providers:

MartinLindhe\VueInternationalizationGenerator\GeneratorProvider::class,

Then generate the include file with php artisan vue-i18n:generate

Adjust your vue app with something like:

import Vue from 'vue';
import VueInternationalization from 'vue-i18n';

import Locales from './vue-i18n-locales.generated.js';

Vue.use(VueInternationalization, {
    lang: 'en',
    locales: Locales
});

...

Parameters

The generator adjusts the strings in order to work with vue-i18n's named formatting, so you can reuse your Laravel translations with parameters.

resource/lang/message.php:

return [
    'hello' => 'Hello :name',
];

in vue-i18n-locales.generated.js:

...
    "hello": "Hello {name}",
...

Blade template:

<div class="message">
    <p>{{ trans('message.hello', ['name' => 'visitor']) }}</p>
</div>

Vue template:

<div class="message">
    <p>{{ $t('message.hello', {name: 'visitor'}) }}</p>
</div>

Notices

Pluralization don't work with vue-i18n

About

Generates a vue-i18n compatible include file from your Laravel translations

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%