2017 © Pedro Peláez
 

library laravel-vue-i18n-generator

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

image

martinlindhe/laravel-vue-i18n-generator

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

  • Wednesday, April 4, 2018
  • by martinlindhe
  • Repository
  • 10 Watchers
  • 125 Stars
  • 83,353 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 26 Forks
  • 3 Open issues
  • 31 Versions
  • 23 % Grown

The README.md

About

NO LONGER MAINTAINED, (*1)

Build Status, (*2)

Laravel 5 package that allows you to share your Laravel localizations with your vue front-end, using vue-i18n or vuex-i18n., (*3)

Laravel 5.7 notice!

Configuration paths have changed in Laravel 5.7, in order for this package to function properly you need to configure correct paths for jsPath and jsFile in your config\vue-i18n-generator.php., (*4)

Install the package

In your project: composer require martinlindhe/laravel-vue-i18n-generator --dev, (*5)

For Laravel 5.4 and below:

For older versions of the framework:, (*6)

Register the service provider in config/app.php, (*7)

MartinLindhe\VueInternationalizationGenerator\GeneratorProvider::class,

Next, publish the package default config:, (*8)

php artisan vendor:publish --provider="MartinLindhe\VueInternationalizationGenerator\GeneratorProvider"

Using vue-i18n

Next, you need to install one out of two supported VueJs i18n libraries. We support vue-i18n as default library. Beside that we also support vuex-i18n., (*9)

When you go with the default option, you only need to install the library through your favorite package manager., (*10)

vue-i18n

npm i --save vue-i18n
yarn add vue-i18n

Then generate the include file with, (*11)

php artisan vue-i18n:generate

Assuming you are using a recent version of vue-i18n (>=6.x), adjust your vue app with something like:, (*12)

import Vue from 'vue';
import VueInternationalization from 'vue-i18n';
import Locale from './vue-i18n-locales.generated';

Vue.use(VueInternationalization);

const lang = document.documentElement.lang.substr(0, 2);
// or however you determine your current app locale

const i18n = new VueInternationalization({
    locale: lang,
    messages: Locale
});

const app = new Vue({
    el: '#app',
    i18n,
    components: {
       ...
    }
}

For older vue-i18n (5.x), the initialization looks something like:, (*13)

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

Vue.use(VueInternationalization);

Vue.config.lang = 'en';

Object.keys(Locales).forEach(function (lang) {
  Vue.locale(lang, Locales[lang])
});

...

Using vuex-i18n

vuex-i18n

npm i --save vuex-i18n
yarn add vuex-i18n vuex

Next, open config/vue-i18n-generator.php and do the following changes:, (*14)

- 'i18nLib' => 'vue-i18n',
+ 'i18nLib' => 'vuex-i18n',

Then generate the include file with, (*15)

php artisan vue-i18n:generate

Assuming you are using a recent version of vuex-i18n, adjust your vue app with something like:, (*16)

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

const store = new Vuex.Store();

Vue.use(vuexI18n.plugin, store);

Vue.i18n.add('en', Locales.en);
Vue.i18n.add('de', Locales.de);

// set the start locale to use
Vue.i18n.set(Spark.locale);

require('./components/bootstrap');

var app = new Vue({
    store,
    mixins: [require('spark')]
});

Output Formats

You can specify the output formats from es6, umd, or json with the --format option. (defaults to es6), (*17)

php artisan vue-i18n:generate --format {es6,umd,json}

Use case example for UMD module

php artisan vue-i18n:generate --format umd

An UMD module can be imported into the browser, build system, node and etc., (*18)

Now you can include the generated script in the browser as a normal script and reference it with window.vuei18nLocales., (*19)



// in your js
Vue.use(VueI18n)
Vue.config.lang = Laravel.language
Object.keys(window.vuei18nLocales).forEach(function (lang) {
  Vue.locale(lang, window.vuei18nLocales[lang])
})

You can still require/import it in your build system as stated above., (*20)

One advantage of doing things like this is you are not obligated to do a build of your javascript each time a the translation files get changed/saved. A good example is if you have a backend that can read and write to your translation files (like Backpack). You can listen to a save event there and call vue-i18n-generator., (*21)

Generating Multiple Files

Sometimes you may want to generate multiple files as you want to make use of lazy loading. As such, you can specify that the generator produces multiple files within the destination directory., (*22)

There are two options: 1. One file per laravel module language file using switch --multi 2. One file per locale using switch --multi-locales, (*23)

php artisan vue-i18n:generate --multi{-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., (*24)

resource/lang/message.php:, (*25)

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

in vue-i18n-locales.generated.js:, (*26)

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

Blade template:, (*27)

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

Vue template:, (*28)

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

Notices

  • The generated file is an ES6 module.

The more sophisticated pluralization localization as described here is not supported since neither vue-i18n or vuex-i18n support this., (*29)

License

Under MIT, (*30)

The Versions

04/04 2018

dev-master

9999999-dev http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

06/03 2018

0.1.28

0.1.28.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

06/03 2018

0.1.27

0.1.27.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

05/03 2018

0.1.26

0.1.26.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

05/03 2018

0.1.25

0.1.25.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

05/03 2018

0.1.24

0.1.24.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

05/03 2018

dev-fixes

dev-fixes http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

10/02 2018

0.1.23

0.1.23.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

08/02 2018

0.1.22

0.1.22.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

25/12 2017

0.1.21

0.1.21.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

21/12 2017

0.1.20

0.1.20.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

15/10 2017

0.1.19

0.1.19.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

10/08 2017

0.1.18

0.1.18.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

29/07 2017

0.1.17

0.1.17.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

19/07 2017

0.1.16

0.1.16.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

11/07 2017

0.1.15

0.1.15.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

05/07 2017

0.1.14

0.1.14.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

12/06 2017

0.1.13

0.1.13.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

21/03 2017

0.1.12

0.1.12.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

07/02 2017

0.1.11

0.1.11.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

25/01 2017

0.1.10

0.1.10.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

25/01 2017

0.1.9

0.1.9.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

29/12 2016

0.1.8

0.1.8.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

01/11 2016

0.1.7

0.1.7.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

19/07 2016

0.1.6

0.1.6.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

27/11 2015

0.1.5

0.1.5.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

27/11 2015

0.1.4

0.1.4.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

09/11 2015

0.1.3

0.1.3.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

09/11 2015

0.1.2

0.1.2.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

09/11 2015

0.1.1

0.1.1.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n

09/11 2015

0.1.0

0.1.0.0 http://github.com/martinlindhe/laravel-vue-i18n-generator

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Lindhe

laravel vue-i18n