PHPackages                             thepinecode/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. thepinecode/i18n

Abandoned → [conedevelopment/i18n](/?search=conedevelopment%2Fi18n)Project[Localization &amp; i18n](/categories/localization)

thepinecode/i18n
================

Push your translations to the front-end.

v1.5.0(1y ago)12928.6k22[1 PRs](https://github.com/conedevelopment/i18n/pulls)1MITPHPPHP ^8.0 || ^8.1CI passing

Since Oct 31Pushed 1y ago4 watchersCompare

[ Source](https://github.com/conedevelopment/i18n)[ Packagist](https://packagist.org/packages/thepinecode/i18n)[ RSS](/packages/thepinecode-i18n/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (29)Used By (1)

I18n
====

[](#i18n)

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

A nice tool for SPAs and front-end heavy applications.

If you have any question how the package works, we suggest to read this post: [Using Laravel’s Localization in JS](https://pineco.de/using-laravels-localization-js/).

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

[](#getting-started)

You can install the package with composer, running the `composer require conedevelopment/i18n` command.

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

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

You can use the `@translations` blade directive. This directive automatically wraps 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 `Pine\I18n\I18nServiceProvider` provider. After publishing you can find your fresh copy in the `resources/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 translator = 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 versions are separated by 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 placeholders.

```
[
    '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
```

### Package translations

[](#package-translations)

Thanks to the idea of [Jonathan](https://github.com/sardoj), package translations are supported by default. You can access to the translations as in Laravel, using the predefined namespace.

```
translator.trans('courier::messages.message');
```

Multiple locales
----------------

[](#multiple-locales)

Multiple locales are supported. You can change the application's locale anytime. Behind the scenes the proper translations will be rendered, if it exists.

Fallback locales
----------------

[](#fallback-locales)

If there are no translations is not available in the current language, the package will look for the fallback locale's translations. If there is no translations available in the fallback locale, the missing translations won't appear.

Performance
-----------

[](#performance)

The translations are generated when the views are compiled. It means they are cached and stored as strings in the compiled views. It's much more performance friendly than generating them on runtime or running and AJAX request to fetch the translations.

Behind the scenes there is a switch - case that determines which translations should be present, based on the current locale. This way only the current translations are pushed to the window object and not all of them.

> Note: On local environment the cached views are getting cleared to keep translations fresh.

Contribute
----------

[](#contribute)

If you found a bug or you have an idea connecting the package, feel free to open an issue.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance43

Moderate activity, may be stable

Popularity42

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 91.6% 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 ~99 days

Recently: every ~379 days

Total

28

Last Release

447d ago

Major Versions

v0.9.2 → v1.0.02020-09-16

PHP version history (5 changes)v0.1.0PHP ^7.0

v0.4.0PHP ^7.1

v0.8.0PHP ^7.2.5

v1.1.0PHP ^7.2.5 || ^8.0

v1.3.0PHP ^8.0 || ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/71387432?v=4)[Cone](/maintainers/conedevelopment)[@conedevelopment](https://github.com/conedevelopment)

---

Top Contributors

[![iamgergo](https://avatars.githubusercontent.com/u/6567179?v=4)](https://github.com/iamgergo "iamgergo (98 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (3 commits)")[![RamyTalal](https://avatars.githubusercontent.com/u/188874?v=4)](https://github.com/RamyTalal "RamyTalal (3 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (2 commits)")[![herpaderpaldent](https://avatars.githubusercontent.com/u/6583519?v=4)](https://github.com/herpaderpaldent "herpaderpaldent (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[barryvdh/laravel-translation-manager

Manage Laravel Translations

1.7k3.6M17](/packages/barryvdh-laravel-translation-manager)[mariuzzo/laravel-js-localization

Laravel Localization in JavaScript

6073.9M3](/packages/mariuzzo-laravel-js-localization)[kkomelin/laravel-translatable-string-exporter

Translatable String Exporter for Laravel

3291.4M10](/packages/kkomelin-laravel-translatable-string-exporter)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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