Download the PHP package barbosa89/laravel-vue-i18n-generator without Composer
On this page you can find all versions of the php package barbosa89/laravel-vue-i18n-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download barbosa89/laravel-vue-i18n-generator
More information about barbosa89/laravel-vue-i18n-generator
Files in barbosa89/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/barbosa89/laravel-vue-i18n-generator
Informations about the package laravel-vue-i18n-generator
Laravel vue-i18n generator
Laravel package that allows you to share your Laravel localizations with your VueJS front-end, using vue-i18n or vuex-i18n. Tested versions: Laravel >=6.x.
Laravel 9 notice!
The new version of the framework moved the language folder out of the resources folder, so you need to update the langPath in the config file:
You can also set the environment variable to assign the path.
Install the package
In your project:
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, <=8.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:
License
Under MIT
All versions of laravel-vue-i18n-generator with dependencies
ext-json Version *
ext-mbstring Version *
illuminate/console Version ^6.0|^7.0|^8.0|^9.0
illuminate/support Version ^6.0|^7.0|^8.0|^9.0