2017 © Pedro Peláez
 

library jstrans

Use Laravel translations in javascript

image

misterpaladin/jstrans

Use Laravel translations in javascript

  • Tuesday, June 6, 2017
  • by MisterPaladin
  • Repository
  • 1 Watchers
  • 4 Stars
  • 1,956 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 10 Versions
  • 1 % Grown

The README.md

JSTrans

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Use Laravel translations in javascript, (*2)

Other languages: - Russian, (*3)

Installation

Install package:, (*4)

$ composer require misterpaladin/jstrans

Add JSTransServiceProvider to your config/app.php:, (*5)

<?php

// ...

'providers' => [
    MisterPaladin\JSTrans\JSTransServiceProvider::class,
],

Publish config:, (*6)

$ php artisan vendor:publish --tag=jstrans

Usage

Edit config/jstrans.php, add translations you wish to use in javascript:, (*7)

return [
    'validation',
];

Include this script in your views before your javascript files:, (*8)

<script src="/vendor/misterpaladin/jstrans/js/jstrans.js" type="text/javascript"></script>

And use it in your javascript like Laravel's trans() function:, (*9)

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:, (*10)

@jstrans([
    'validation' => 'new value',
])

@jstrans([
    'foo' => trans('bar'),
    'fooo' => 'baaar',
])
var validation = jstrans('validation'); // Will return 'new value', instead of 'validation.php' array

The Versions

06/06 2017

dev-master

9999999-dev

Use Laravel translations in javascript

  Sources   Download

MIT

by Eugene Min

06/06 2017

1.3.3

1.3.3.0

Use Laravel translations in javascript

  Sources   Download

MIT

by Eugene Min

06/09 2016

1.3.2

1.3.2.0

Use Laravel translations in javascript

  Sources   Download

MIT

by Eugene Min

06/09 2016

1.3.1

1.3.1.0

Use Laravel translations in javascript

  Sources   Download

MIT

by Eugene Min

16/06 2016

1.3

1.3.0.0

Use Laravel translations in javascript

  Sources   Download

MIT

by Eugene Min

05/06 2016

1.2.2

1.2.2.0

Use Laravel translations in javascript

  Sources   Download

MIT

by Eugene Min

05/06 2016

1.2.1

1.2.1.0

Use Laravel translations in javascript

  Sources   Download

MIT

by Eugene Min

05/06 2016

1.2

1.2.0.0

Use Laravel translations in javascript

  Sources   Download

ISC

by Eugene Min

04/06 2016

1.1

1.1.0.0

Use Laravel translations in javascript

  Sources   Download

ISC

by Eugene Min

03/06 2016

1.0

1.0.0.0

Use Laravel translations in javascript

  Sources   Download

ISC

by Eugene Min