PHPackages                             grajewsky/laravel-i18n - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. grajewsky/laravel-i18n

ActiveProject[Localization &amp; i18n](/categories/localization)

grajewsky/laravel-i18n
======================

JavaScript translations provider

v2.0.2(3y ago)0462MITPHPPHP ^7.0|^8.0

Since Dec 12Pushed 3y ago1 watchersCompare

[ Source](https://github.com/grajewsky/laravel-i18n)[ Packagist](https://packagist.org/packages/grajewsky/laravel-i18n)[ RSS](/packages/grajewsky-laravel-i18n/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (4)Used By (0)

I18n
====

[](#i18n)

Push your Laravel translations to the front-end and use them easily with JavaScript.

The JSON based translations are not supported!

Getting started
---------------

[](#getting-started)

You can install the package with composer, running the `composer require grajewsky/laravel-i18n` command.

### Laravel 5.4 and below

[](#laravel-54-and-below)

You have to register the service provider manually. Go to the `config/app.php` file and add the `Grajewsky\Laravel\I18n\Providers\I18nServiceProvider::class` to the providers array.

### Laravel 5.5 and up

[](#laravel-55-and-up)

Package is auto-discover

### Configuration

[](#configuration)

```
> php artisan vendor:publish
```

You can add your own i18n paths providers only what u must to do is implements Grajewsky\\Laravel\\I18n\\Interfaces\\I18nProvider

- getI18nPath(): string
- getLocale(): string;
- getNamespace(): string;

and add I18nProvider into `config/i18n.php` Fullnamespace\\MyI18nProvider::class

Translations in view files
--------------------------

[](#translations-in-view-files)

You can use the `@translations` blade directive. This directive automatically wrap the translations to a `` tag.

```
@translations

window['translations'] = { auth: {...}, validation: {...} }
```

You may override the default key for the translations. You can do that by passing a string to the blade directive.

```
@translations ('myTranslations')

window['myTranslations'] = { auth: {...}, validation: {...} }
```

Publishing and using the JavaScript library
-------------------------------------------

[](#publishing-and-using-the-javascript-library)

Use the `php artisan vendor:publish` command and choose the `Grajewsky\Laravel\I18n\Providers\I18nServiceProvider::class` provider. After publishing you can find your fresh copy in the `resources/assets/js/vendor` folder.

### Using the I18n.js

[](#using-the-i18njs)

Then you can import the *I18n* class and assign it to the `window` object.

```
import I18n from './vendor/I18n';
window.I18n = I18n;
```

### Initializing a translation instance

[](#initializing-a-translation-instance)

From this point you can initialize the translation service anywhere from your application.

```
let translator = new I18n;
```

By default, it uses the `translations` key in the `window` object. If you want to use the custom one you set in the blade directive, pass the same key to the constructor.

```
let traslator = new I18n('myTranslations');
```

### Using it as a Vue service

[](#using-it-as-a-vue-service)

If you want to use it from Vue templates directly you can extend Vue with this easily.

```
Vue.prototype.$I18n = new I18n;
```

You can call it from your template or the script part of your component like below:

```

    {{ $I18n.trans('some.key') }}

```

```
computed: {
    translations: {
        something: this.$I18n.trans('some.key')
    }
}
```

### Methods

[](#methods)

The package comes with two methods on JS side. The `trans()` and the `trans_choice()`.

#### `trans()`

[](#trans)

The `trans` method accepts the key of the translation and the attributes what we want to replace, but it's optional.

```
translator.trans('auth.failed');

// These credentials do not match our records.

translator.trans('auth.throttle', { seconds: 60 });

// Too many login attempts. Please try again in 60 seconds.
```

#### `trans_choice()`

[](#trans_choice)

The `trans_choice` method determines if the translation should be pluralized or nor by the given cout. Also, it accepts the attributes we want to replace.

Let's say we have the following translation line:

```
[
    'attempts' => 'Be careful, you have :attempts attempt left.|You still have :attempts attempts left.',
]
```

> Note, the plural and the singular verions are separated with the `|` character!

```
translator.trans_choice('auth.attempts', 1, { attempts: 'only one' });

// Be careful, you have only one attempt left.

translator.trans_choice('auth.attempts', 4, { attempts: 'less than five' });

// You still have less than five attempts left.
```

Like in Laravel, you have the ability to set ranges for the pluralization. Also, you can replace placeholders like before.

```
[
    'apples' => '{0} There are none|[1,19] There are some (:number)|[20,*] There are many (:number)',
]
```

> You can separate more than two choices with the `|` character.

```
translator.trans_choice('messages.apples', 0);

// There are none

translator.trans_choice('auth.attempts', 8, { number: 8 });

// There are some (8)

translator.trans_choice('auth.attempts', 25, { number: 25 });

// There are many (25)
```

### Transforming replacement parameters

[](#transforming-replacement-parameters)

Like in Laravel's functionality, you can transform your parameters to upper case, or convert only the first character to capital letter. All you need to do, to modify your translations.

```
[
    'welcome' => 'Welcome, :NAME',
    'goodbye' => 'Goodbye, :Name',
]
```

> If you want, you can pass the same parameter with different modifiers in one line as well, like `:NAME`, `:name` or `:Name`.

```
translator.trans('messages.welcome', { name: 'pine' });

// Welcome, PINE

translator.trans('messages.goodbye', { name: 'pine' });

// Goodbye, Pine
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~718 days

Total

3

Last Release

1272d ago

Major Versions

v1.0 → v2.0.12019-02-28

PHP version history (2 changes)v1.0PHP ^7.0

v2.0.2PHP ^7.0|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/08fec7d2ad35f456cd3ef16e222d9344af07fb4bf0ee50e19c6ccb076552af37?d=identicon)[grajewsky](/maintainers/grajewsky)

---

Top Contributors

[![grajewsky](https://avatars.githubusercontent.com/u/17883113?v=4)](https://github.com/grajewsky "grajewsky (3 commits)")

### Embed Badge

![Health badge](/badges/grajewsky-laravel-i18n/health.svg)

```
[![Health](https://phpackages.com/badges/grajewsky-laravel-i18n/health.svg)](https://phpackages.com/packages/grajewsky-laravel-i18n)
```

###  Alternatives

[symfony/translation

Provides tools to internationalize your application

6.6k836.5M2.1k](/packages/symfony-translation)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

169661.4M4.8k](/packages/nesbot-carbon)[joedixon/laravel-translation

A tool for managing all of your Laravel translations

717911.4k11](/packages/joedixon-laravel-translation)[illuminate/translation

The Illuminate Translation package.

6936.4M495](/packages/illuminate-translation)[lajax/yii2-translate-manager

Translation management extension for Yii 2

227578.8k13](/packages/lajax-yii2-translate-manager)[larswiegers/laravel-translations-checker

Make sure your laravel translations are checked and are included in all languages.

256423.2k2](/packages/larswiegers-laravel-translations-checker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
