misterpaladin/jstrans

Use Laravel translations in javascript
3,128 4
Install
composer require misterpaladin/jstrans
Latest Version:1.3.3
License:MIT
Last Updated:Jun 5, 2017
Links: GitHub  ·  Packagist
Maintainer: MisterPaladin

JSTrans

Latest Stable Version Total Downloads Latest Unstable Version License

Use Laravel translations in javascript

Other languages:

Installation

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

Usage

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.'

Custom values

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

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

637,827,751 9,703
laravel/framework

The Laravel Framework.

589,172,971 34,950
laravel/tinker

Powerful REPL for the Laravel framework.

498,216,183 7,442
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

413,412,504 609
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

394,964,158 4,660

Version History

Version Released License
1.3.3 MIT
1.3.2 MIT
1.3.1 MIT
1.3 MIT
1.2.2 MIT