PHPackages                             aitor24/laralang - 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. aitor24/laralang

ActiveTranslations

aitor24/laralang
================

This package let you translate strings from any language to another in laravel 5.X

4.0.1(8y ago)443159[1 PRs](https://github.com/24aitor/laralang/pulls)MITPHPPHP &gt;=5.6.4

Since Sep 28Pushed 8y ago4 watchersCompare

[ Source](https://github.com/24aitor/laralang)[ Packagist](https://packagist.org/packages/aitor24/laralang)[ RSS](/packages/aitor24-laralang/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (1)Versions (36)Used By (0)

Laralang
========

[](#laralang)

[![](https://camo.githubusercontent.com/8f8ba943db79231aeb5b2de7dafc6a36c3676b62ef2baacb1e6c4617e40dce04/687474703a2f2f692e696d6775722e636f6d2f31315476636f682e706e67)](https://camo.githubusercontent.com/8f8ba943db79231aeb5b2de7dafc6a36c3676b62ef2baacb1e6c4617e40dce04/687474703a2f2f692e696d6775722e636f6d2f31315476636f682e706e67)

 [![StyleCI](https://camo.githubusercontent.com/1b47c12c83d69fd6f7491cbc9e8fac29e7500e4bba01063064346eeba2b9ec6d/68747470733a2f2f7374796c6563692e696f2f7265706f732f36393436303831352f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/69460815) [![Scrutinizer](https://camo.githubusercontent.com/bb7aed7a59b6f5f82e94e9095dd76dcae948e3a7855295113014b136d5883638/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f32346169746f722f6c6172616c616e672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/24aitor/laralang/?branch=master) [![Latest Stable Version](https://camo.githubusercontent.com/cc6ee77f1d375b72bddcad4c9f95f82b7bb21df4acd3c575f7ca5705363dc36e/68747470733a2f2f706f7365722e707567782e6f72672f6169746f7232342f6c6172616c616e672f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/aitor24/laralang) [![License](https://camo.githubusercontent.com/fabd250b8c8ba1fa0a8db695ef3fde18ee3d239e495c0fd92353c3026967f048/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f32346169746f722f6c6172616c616e672e7376673f7374796c653d666c61742d737175617265)](https://raw.githubusercontent.com/24aitor/laralang/master/LICENSE)

What is Laralang?
-----------------

[](#what-is-laralang)

Laralang is a laravel packages that allows you to translate your app or parts of your app from views using translations services like google or mymemory, and then store it on your DB to filter and manage easily from our admin panel.

Moreover, allows you to translate PHP files easily and then save lot of time to you.

Why use Laralang?
-----------------

[](#why-use-laralang)

Personally I think the best way to translate your website is using the Laravel methods such as `@lang()` but sometimes it's impossible. Imagine you have a blog, and you need to translate it to different languages. With Laralang it's soo easy to do it, only place a little code like following example and laralang will translate it from your favourite translation service or well loading a stored translation on your database.

```
{{ Laralang::trans($post->content) }}
```

Getting Started
---------------

[](#getting-started)

### Step 1. Install it with composer

[](#step-1-install-it-with-composer)

Running the command below:

```
composer require aitor24/laralang

```

### Step 2. Register service provider &amp; aliases

[](#step-2-register-service-provider--aliases)

Include the line below to config/app.php inside providers array :

```
Aitor24\Laralang\LaralangServiceProvider::class,
```

Include the line below to config/app.php inside aliases array :

```
'Laralang'   => Aitor24\Laralang\Facades\Laralang::class,
```

### Step 3. Publish vendor

[](#step-3-publish-vendor)

It will publish assets and config file.

Running the command below:

```
php artisan vendor:publish

```

### Step 4. Migrate

[](#step-4-migrate)

Running the command below:

```
php artisan migrate

```

### Step 5. Configure defalt values

[](#step-5-configure-defalt-values)

**STRONGLY IMPORTANT:** Change the password on config *(Default password: laralangAdmin )*

Apart from the password, the rest of default values can be modified also on `config/laralang.php`. Furthermore you can modify these in a specific translation with the functions below.

**Available Translators:** Google Translator, MyMemory, Apertium (Strongly not recomended)

*config values for translators*: 'google', 'mymemory', 'apertium'

Using laralang
--------------

[](#using-laralang)

### Simple examples of use

[](#simple-examples-of-use)

Then few examples of use laralang:

```

    {!! Laralang::trans('Hello world!') !!}

    {!! Laralang::trans('Hello world!')->debug(true) !!}

    {!! Laralang::trans('Hello world!')->to('es') !!}

    {!! Laralang::trans('Hello world!')->to('ca') !!}

    {!! Laralang::trans('Hello world!')->to('ca')->debug(true) !!}

    {!! Laralang::trans('Hallo welt!')->from('de')->to('fr') !!}

    {!! Laralang::trans('Hello world!')->to('pt') !!}

    {!! Laralang::trans('Hello world!')->to('de') !!}

    {!! Laralang::trans('Hello world!')->to('ml') !!}

    {!! Laralang::trans('Hello world!')->to('zh')->translator('apertium') !!}

    From langs:
    @foreach(Laralang::fromLanguages() as $lang)
        {{$lang}}
    @endforeach

    To langs:
    @foreach(Laralang::toLanguages() as $lang)
        {{$lang}}
    @endforeach

```

**NOTE: Use {{ }} statements if translations comes from users to prevent XSS atacks**

Then the result:

[![Result of example](https://camo.githubusercontent.com/1033e3b30b9c8b69521979ee827bdc2cc8161d75b38389b1d99dcc321f7f8f54/687474703a2f2f692e696d6775722e636f6d2f685773524a4c612e706e67)](https://camo.githubusercontent.com/1033e3b30b9c8b69521979ee827bdc2cc8161d75b38389b1d99dcc321f7f8f54/687474703a2f2f692e696d6775722e636f6d2f685773524a4c612e706e67)

Admin panel
-----------

[](#admin-panel)

### Firsts steps

[](#firsts-steps)

**First you should be logged into loaralang**

*Route prefix can be changed on your config file, but by default it's laralang*

- How to acces to panel?

You should visit next url:

or in localhost you should visit

Then you should see the laralang login page (photo below)

[![Laralang login page](https://camo.githubusercontent.com/106fbb6e851c55cd8d78afa05899c8180a5a2adf120d0b3b513bce41e746c7e6/687474703a2f2f692e696d6775722e636f6d2f626a514a6948512e706e67)](https://camo.githubusercontent.com/106fbb6e851c55cd8d78afa05899c8180a5a2adf120d0b3b513bce41e746c7e6/687474703a2f2f692e696d6775722e636f6d2f626a514a6948512e706e67)

Now you must enter the password you set on [Step 5](#step-5.-configure-defalt-values) and then click login to manage your translations as can be seen on photos below!

[![View of translations](https://camo.githubusercontent.com/3be333b8bb797dfb9f17783edf94f4c4a1d52d7659e2957e94f0476b20607c5c/687474703a2f2f692e696d6775722e636f6d2f4e49463879714c2e706e67)](https://camo.githubusercontent.com/3be333b8bb797dfb9f17783edf94f4c4a1d52d7659e2957e94f0476b20607c5c/687474703a2f2f692e696d6775722e636f6d2f4e49463879714c2e706e67)

[![Editing translation #3](https://camo.githubusercontent.com/54cb08bf976fe7f56bbe762056aed778e90a9938645a4dd79ee54b11cf19c0c0/687474703a2f2f692e696d6775722e636f6d2f736d4b387863742e706e67)](https://camo.githubusercontent.com/54cb08bf976fe7f56bbe762056aed778e90a9938645a4dd79ee54b11cf19c0c0/687474703a2f2f692e696d6775722e636f6d2f736d4b387863742e706e67)

### Filtering translations

[](#filtering-translations)

Laralang also lets you filter translations by *from\_lang* and / or *to\_lang*. Below you have an example:

First we must access to filter view in route  or well accessing across menu.

[![Menu](https://camo.githubusercontent.com/2fd7a8d09c581b89ce86bc8221175578809b3f6908ddfc1414196cdad3d68b2b/687474703a2f2f692e696d6775722e636f6d2f6f3142346d31482e706e67)](https://camo.githubusercontent.com/2fd7a8d09c581b89ce86bc8221175578809b3f6908ddfc1414196cdad3d68b2b/687474703a2f2f692e696d6775722e636f6d2f6f3142346d31482e706e67)

Then you can select from which language provides the originals strings and then from which language are translated this string with two selectors:

[![Filtering](https://camo.githubusercontent.com/70a9b00d96d5cf0bd60d66037f5d0290cd3c1661dd75b4d7ec21fba120e5a726/687474703a2f2f692e696d6775722e636f6d2f5a52544f4e4e452e706e67)](https://camo.githubusercontent.com/70a9b00d96d5cf0bd60d66037f5d0290cd3c1661dd75b4d7ec21fba120e5a726/687474703a2f2f692e696d6775722e636f6d2f5a52544f4e4e452e706e67)

Then the result:

[![Filtering result](https://camo.githubusercontent.com/deb55a7ca8222e9d4b8ca5642e2ab0f45ac89beba224ba7e18acd81c33541886/687474703a2f2f692e696d6775722e636f6d2f6c726b366d7a522e706e67)](https://camo.githubusercontent.com/deb55a7ca8222e9d4b8ca5642e2ab0f45ac89beba224ba7e18acd81c33541886/687474703a2f2f692e696d6775722e636f6d2f6c726b366d7a522e706e67)

### Translations via api

[](#translations-via-api)

There exists an api to get translated text. First of all you should enable it on config, then you should configure ajax as explained in [laravel official site](https://laravel.com/docs/5.3/csrf#csrf-x-csrf-token) and then call api (method=POST)

```
$.post('{{route("laralang::apiTranslate")}}', {'string' : 'This is my string to translate', 'to' : 'de'}, function(response) {
    var translatedText = response.translatedText;
}, 'json');
```

Translating PHP files
---------------------

[](#translating-php-files)

Laralang can generate PHP translations files quickly by translating from english to language you want and save a lot of time!

After login to admin panel, you will find something like this:

[![Home](https://camo.githubusercontent.com/4b96e46743921c51a68f9aea7227ab16a700f174ec3d23f5a105d2e1d957cd49/68747470733a2f2f73632d63646e2e7363616c65656e67696e652e6e65742f692f34616562353938376232663761316632656531333235303930336433633331342e706e67)](https://camo.githubusercontent.com/4b96e46743921c51a68f9aea7227ab16a700f174ec3d23f5a105d2e1d957cd49/68747470733a2f2f73632d63646e2e7363616c65656e67696e652e6e65742f692f34616562353938376232663761316632656531333235303930336433633331342e706e67)

Here you simply click on translate PHP files and then you should see this view:

[![Translations](https://camo.githubusercontent.com/3fe3e0261161ad80cdf9984c091dfbd884990ae5ff4e5687a740700f0d8fe47d/68747470733a2f2f73632d63646e2e7363616c65656e67696e652e6e65742f692f63643335626534316164356333656138636630396534653030333763343833622e706e67)](https://camo.githubusercontent.com/3fe3e0261161ad80cdf9984c091dfbd884990ae5ff4e5687a740700f0d8fe47d/68747470733a2f2f73632d63646e2e7363616c65656e67696e652e6e65742f692f63643335626534316164356333656138636630396534653030333763343833622e706e67)

Here you can click translate and all files of resources/lang/en will be translated into languages you choose in the form input!

Then on resources/lang/ you will find a folder for each language with it's respective files translated.

API
---

[](#api)

### trans() method

[](#trans-method)

This functions is used to get a translation from a string to another language specified on default values, on app\_locale or in every function.

To simplify work we've implemented another package [(Localizer)](https://github.com/24aitor/Localizer) to set app\_locale via middleware and it allows to get user browser language to set it as app\_locale easily.

#### Functions of trans()

[](#functions-of-trans)

**from()**

It sets the language of the string to translate in a specific translation.

*Default: en*

**to()**

It sets the language that you'll output in a specific translation.

*Default: app\_locale*

**debug()**

Debug option let you to know the reason of an unexpected result with colorful messages in a specific translation.

*Default: false*

**Save()**

Save option let you to save a specific translation.

*Default: false*

---

### fromLanguages() method

[](#fromlanguages-method)

Returns an array with all languages from provides strings to translate.

### toLanguages() method

[](#tolanguages-method)

Returns an array with all languages that at least one string has been translated.

### getLanguages() method

[](#getlanguages-method)

Returns an array with \['key' =&gt; 'value'\] where key is a language and value is an acronym from all languages tested in laralang.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 97.1% 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 ~13 days

Recently: every ~40 days

Total

34

Last Release

3015d ago

Major Versions

1.2.2 → 2.02016-10-30

2.3 → 3.02016-11-21

3.7.3 → 4.0.02017-08-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/a56e20e7af7971bdf153b60a506c54be8e2bbeb3a7cd15e1ac04247829299040?d=identicon)[24aitor](/maintainers/24aitor)

---

Top Contributors

[![24aitor](https://avatars.githubusercontent.com/u/20477883?v=4)](https://github.com/24aitor "24aitor (166 commits)")[![ConsoleTVs](https://avatars.githubusercontent.com/u/6124435?v=4)](https://github.com/ConsoleTVs "ConsoleTVs (5 commits)")

---

Tags

languagelaravellaravel-5-packagetranslation

### Embed Badge

![Health badge](/badges/aitor24-laralang/health.svg)

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

###  Alternatives

[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169175.3k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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