Download the PHP package martinlindhe/laravel-vue-i18n-generator without Composer
On this page you can find all versions of the php package martinlindhe/laravel-vue-i18n-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download martinlindhe/laravel-vue-i18n-generator
More information about martinlindhe/laravel-vue-i18n-generator
Files in martinlindhe/laravel-vue-i18n-generator
Package laravel-vue-i18n-generator
Short Description Generates a vue-i18n compatible include file from your Laravel translations.
License MIT
Homepage http://github.com/martinlindhe/laravel-vue-i18n-generator
Informations about the package laravel-vue-i18n-generator
About
NO LONGER MAINTAINED
Laravel 5 package that allows you to share your Laravel localizations with your vue front-end, using vue-i18n or vuex-i18n.
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
.
Install the package
In your project:
For Laravel 5.4 and below:
For older versions of the framework:
Register the service provider in
Next, publish the package default config:
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.
When you go with the default option, you only need to install the library through your favorite package manager.
vue-i18n
Then generate the include file with
Assuming you are using a recent version of vue-i18n (>=6.x), adjust your vue app with something like:
For older vue-i18n (5.x), the initialization looks something like:
Using vuex-i18n
vuex-i18n
Next, open config/vue-i18n-generator.php
and do the following changes:
Then generate the include file with
Assuming you are using a recent version of vuex-i18n, adjust your vue app with something like:
Output Formats
You can specify the output formats from es6
, umd
, or json
with the --format
option. (defaults to es6
)
Use case example for UMD module
An UMD module can be imported into the browser, build system, node and etc.
Now you can include the generated script in the browser as a normal script and reference it with window.vuei18nLocales.
You can still require/import it in your build system as stated above.
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.
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.
There are two options:
- One file per laravel module language file using switch
- One file per locale using switch
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:
in vue-i18n-locales.generated.js:
Blade template:
Vue template:
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.
License
Under MIT
All versions of laravel-vue-i18n-generator with dependencies
ext-json Version *
ext-mbstring Version *
illuminate/console Version ~5.1.0|~5.2.0|~5.3.0|~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.0|~7.0
illuminate/support Version ~5.1.0|~5.2.0|~5.3.0|~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.0|~7.0