Modular Export of Laravel translations for Front-End and API usage.
Modular Export of Laravel translations for Front-End and API usage., (*2)
This package is inspired from the the way how CMSs built on top of Laravel work and how they are structured into packages for large-scale applications. In these CMSs, each package has its own langdirectory., (*3)
Also, this package has an exclude array to exclude lang files from each lang directory in these modular packages. And finally, an event is emitted after export is done., (*4)
Require this package, with Composer, in the root directory of your project., (*5)
``` bash $ composer require yazeedobaid/laravel-lang, (*6)
## Assets Publishing To publish the config file of the package use: ``` php php artisan vendor:publish --provider=YazeedObaid\Lang\LaravelLangServiceProvider --tag=config
Add this route to your Front-End side or call it as an API. http://your-web-app/js/lang.js, (*7)
The config file contains configurations for the route to use for the translations, a middlewares array for the route to be applied to it. An events channel, to specify the event channel., (*8)
The keys for the 'paths' and 'files_to_exclude' arrays must be the same, since these keys define each package name (alias). Feel free to select you prefered name., (*9)
Below is an example on the path of a package to get its translations with a excluded trans file in that package:, (*10)
``` php 'paths' => [ /** * For each package in your project you can define the relative path to that * package from your root app directory to the lang directory in that package * to use it in export to Vue. The default path to Laravel applications which * is /resources/lang is set by default to you * */, (*11)
/** * Default path is the resources/lang path. * */ 'default' => '/resources/lang', /** * Here you define a path for each package you want to export the * translations for. * */ 'my-package' => '/packages/myPckage/src/resources/lang' ], 'files_to_exclude' => [ /** * In each package you define above in the paths array you can exclude files * in that package and not to include them in export to Vue process. Use the * same key you use above to exclude files in each package. The below is an * example of excluding the auth file in default Laravel translations * location. * */ /*'default' => [ 'auth' ]*/ ]
```, (*12)
This package was inspired from kg-bot/laravel-localization-to-vue., (*13)