sirgrimorum / jslocalization
Put localization translations in js
1.2.7
2021-01-11 10:35 UTC
Requires
- php: >=7.0
- laravel/framework: >=5.4
README
Put localization arrays in JavaScript for Laravel 5.6.
Install
Via Composer
$ composer require sirgrimorum/jslocalization
OPTIONAL: Publish Configuration
$php artisan vendor:publish --tag=config
Usage for localized strings
{!! JSLocalization::get("admin","messages","transmensajes") !!} <script> (function() { alert(transmensajes.admin.error); })(); </script>
Or with blade directives
@jslocalization("admin","error_messages","error") <script> (function() { alert(error.error_messages.permissions); })(); </script>
Using blade directives, remember to clear de view:cache after each change in the localization files:
$php artisan view:clear
Usage for models, objects, arrays and collections
{!! JSLocalization::put(Auth::user(),"currentUser") !!} <script> (function() { alert(currentUser.id); })(); </script>
Or with blade directives
@jsmodel(Auth::user(),"currentUser") <script> (function() { alert(currentUser.id); })(); </script>
Using blade directives, remember to clear de view:cache after each change in the localization files:
$php artisan view:clear
Security
If you discover any security related issues, please email andres.espinosa@grimorum.com instead of using the issue tracker.
Credits
- SirGrimorum link-author
- Grimorum Ltda. link-contributors
License
The MIT License (MIT). Please see License File for more information.