sirgrimorum/jslocalization

Put localization translations in js

1.2.7 2021-01-11 10:35 UTC

This package is auto-updated.

Last update: 2024-11-11 20:01:02 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

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

License

The MIT License (MIT). Please see License File for more information.