| Package Data | |
|---|---|
| Maintainer Username: | MisterPaladin |
| Maintainer Contact: | e.min@milax.com (Eugene Min) |
| Package Create Date: | 2016-06-03 |
| Package Last Update: | 2017-06-05 |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-11-02 03:03:18 |
| Package Statistics | |
|---|---|
| Total Downloads: | 3,122 |
| Monthly Downloads: | 0 |
| Daily Downloads: | 0 |
| Total Stars: | 4 |
| Total Watchers: | 1 |
| Total Forks: | 1 |
| Total Open Issues: | 0 |
Use Laravel translations in javascript
Other languages:
Install package:
$ composer require misterpaladin/jstrans
Add JSTransServiceProvider to your config/app.php:
<?php
// ...
'providers' => [
MisterPaladin\JSTrans\JSTransServiceProvider::class,
],
Publish config:
$ php artisan vendor:publish --tag=jstrans
Edit config/jstrans.php, add translations you wish to use in javascript:
return [
'validation',
];
Include this script in your views before your javascript files:
<script src="/vendor/misterpaladin/jstrans/js/jstrans.js" type="text/javascript"></script>
And use it in your javascript like Laravel's trans() function:
jstrans('validation'); // Will return whole 'validation.php' array
jstrans('validation.accepted'); // Will return 'The :attribute must be accepted.'
jstrans('validation.foo.bar'); // Will return 'validation.foo.bar'
jstrans('validation.accepted', {attribute: 'Test'}); // Will return 'The Test must be accepted.'
You may specify additional values to overwrite localization files:
@jstrans([
'validation' => 'new value',
])
@jstrans([
'foo' => trans('bar'),
'fooo' => 'baaar',
])
var validation = jstrans('validation'); // Will return 'new value', instead of 'validation.php' array