PHPackages                             memdev/laravel-localization-to-vue - 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. memdev/laravel-localization-to-vue

ActiveLibrary

memdev/laravel-localization-to-vue
==================================

Laravel package used to collect all localization files from resources/lang (and custom) directories and sub-directories and make them available as JSON file

03PHP

Since Mar 14Pushed 2y agoCompare

[ Source](https://github.com/memdev/laravel-localization-to-vue)[ Packagist](https://packagist.org/packages/memdev/laravel-localization-to-vue)[ RSS](/packages/memdev-laravel-localization-to-vue/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/9841d78c92c5a24dd1fc51c0fd08b72364b3088435e1dcc3813ccac6622be0b0/68747470733a2f2f706f7365722e707567782e6f72672f6b672d626f742f6c61726176656c2d6c6f63616c697a6174696f6e2d746f2d7675652f762f737461626c65)](https://packagist.org/packages/kg-bot/laravel-localization-to-vue)[![Total Downloads](https://camo.githubusercontent.com/822ccc3d67cbb0a8a3bf500fb2e896668ace78005a143197baaf7b4a9213405d/68747470733a2f2f706f7365722e707567782e6f72672f6b672d626f742f6c61726176656c2d6c6f63616c697a6174696f6e2d746f2d7675652f646f776e6c6f616473)](https://packagist.org/packages/kg-bot/laravel-localization-to-vue)[![Latest Unstable Version](https://camo.githubusercontent.com/44e7c7c9356fb2424702553d49cbabfe94c156f6baa10924b956ee123c2ff486/68747470733a2f2f706f7365722e707567782e6f72672f6b672d626f742f6c61726176656c2d6c6f63616c697a6174696f6e2d746f2d7675652f762f756e737461626c65)](https://packagist.org/packages/kg-bot/laravel-localization-to-vue)[![License](https://camo.githubusercontent.com/8325d6408cf1fccc3e978a16477a409add917f803619de7e724282926c0258a5/68747470733a2f2f706f7365722e707567782e6f72672f6b672d626f742f6c61726176656c2d6c6f63616c697a6174696f6e2d746f2d7675652f6c6963656e7365)](https://packagist.org/packages/kg-bot/laravel-localization-to-vue)[![Monthly Downloads](https://camo.githubusercontent.com/4c0b6e81c4b62f513fefe4a23f5c0673aed69ea22edc48b1427f78bd9887e1ce/68747470733a2f2f706f7365722e707567782e6f72672f6b672d626f742f6c61726176656c2d6c6f63616c697a6174696f6e2d746f2d7675652f642f6d6f6e74686c79)](https://packagist.org/packages/kg-bot/laravel-localization-to-vue)[![Daily Downloads](https://camo.githubusercontent.com/2110db546282c96a16f25d6680145a1c9138a9e0ad0eb72cb9679da7b09eeb73/68747470733a2f2f706f7365722e707567782e6f72672f6b672d626f742f6c61726176656c2d6c6f63616c697a6174696f6e2d746f2d7675652f642f6461696c79)](https://packagist.org/packages/kg-bot/laravel-localization-to-vue)

[![](https://camo.githubusercontent.com/a36899167fca22992a607b62c7749ba925d790197ea89c3696e2d36e82043ee4/68747470733a2f2f696d672e6275796d6561636f666665652e636f6d2f627574746f6e2d6170692f3f746578743d427579206d652061206265657226656d6f6a693df09f8dba26736c75673d4b67426f7426627574746f6e5f636f6c6f75723d35463746464626666f6e745f636f6c6f75723d66666666666626666f6e745f66616d696c793d436f6f6b6965266f75746c696e655f636f6c6f75723d30303030303026636f666665655f636f6c6f75723d464644443030)](https://www.buymeacoffee.com/KgBot)

Laravel Localization To Vue/JSON
================================

[](#laravel-localization-to-vuejson)

This package collects all localizations from resources/lang directory and it's sub-directories and converts them to plain array
which can later be converted to JSON object and used with libraries like Vue, Angular, etc.

Installing
----------

[](#installing)

#### Laravel before version 9

[](#laravel-before-version-9)

```
composer require kg-bot/laravel-localization-to-vue:^1

```

#### Laravel 9

[](#laravel-9)

```
composer require kg-bot/laravel-localization-to-vue:^2

```

### Laravel 8+

[](#laravel-8)

Laravel 8 requires minimum of PHP 7.3. make sure you have at least PHP 7.3 before running composer.

### Laravel 9+

[](#laravel-9-1)

Laravel 9 requires minimum of PHP 8.0.2 make sure you have at least PHP 8.0.2 before running composer.

### Laravel 5.5+

[](#laravel-55)

Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php

```
KgBot\LaravelLocalization\LaravelLocalizationServiceProvider::class
```

and if you want alias add this inside aliases array in config/app.php

```
"ExportLocalization" => "KgBot\\LaravelLocalization\\Facades\\ExportLocalizations"
```

Settings and configuration
--------------------------

[](#settings-and-configuration)

You can export config by running

```
php artisan vendor:publish --provider="KgBot\LaravelLocalization\LaravelLocalizationServiceProvider" --tag=config
```

if you want to parse multiple language directories or some other directory except `lang_path()` you can add multiple paths in config `paths.lang_dirs` inside array.

It can be just one path or multiple paths, for example

```
paths => [lang_path(), app_path('lang'), app_path('Modules/Blog/lang')]
```

You can run your own callback function after export, to do that you must register globally accessible function, for example register `function.php` inside composer files autoload, and add your function inside `config/laravel-localization.php`, key `export_callback`. Example:

```
// helpers/functions.php

if (! function_exists('testExport')) {
    /**
     * Change all instances of :argument to {argument}
     *
     * @param $string
     * @return void
     *
     */
    function testExport($string) {
        array_walk_recursive($string, function (&$v, $k) { $v = preg_replace('/:(\w+)/', '{$1}', $v); });

        return $string;
    }
}

// composer.json
....
"autoload": {
        "files": [
            "helpers/functions.php"
        ],
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
....

// config/laravel-localization.php
...
'export_callback' => 'testExport',
...
```

Usage
=====

[](#usage)

This package can be used in multiple ways, I'll give examples for some of them, but there's really no limitation.

First example would be to add view composed variable and use it in blade views.

```
// inside ServiceProvider

// With alias
use ExportLocalization;

// Without alias
use KgBot\LaravelLocalization\Facades\ExportLocalizations as ExportLocalization;

View::composer( 'view.file', function ( $view ) {

    return $view->with( [
        'messages' => ExportLocalization::export()->toArray(),
    ] );
} );
```

Second way would be to request it over HTTP just like any other file

```

let messages = axios.get('http://localhost/js/localization.js') // This is default route which can be changed in config

```

For this to work, you need to enable the route via `LARAVEL_LOCALIZATION_ROUTE_ENABLE` in your `.env` file or in `config/laravel-localization.php`

You can also export messages to ECMAScript 6 standard JavaScript module with artisan command `php artisan export:messages`

Export for npm localization packages like Lang.js
-------------------------------------------------

[](#export-for-npm-localization-packages-like-langjs)

If you need special format of array that's recognised by some npm localization packages as [Lang.js](https://github.com/rmariuzzo/Lang.js).

```
// Call toFlat() instead of toArray()
ExportLocalization::export()->toFlat()

or

// For CLI usage
php artisan export:messages-flat
```

Some examples why would you use this package and messages over Laravel standard localization
--------------------------------------------------------------------------------------------

[](#some-examples-why-would-you-use-this-package-and-messages-over-laravel-standard-localization)

```
// Inside blade view

    window.default_locale = "{{ config('app.locale') }}";
    window.fallback_locale = "{{ config('app.fallback_locale') }}";
    window.messages = @json($messages);

```

```
// And optionaly you can then use it in any JavaScript file or Vue.js component

// app.js
import Vue from 'vue';
import Lang from 'lang.js';

const default_locale = window.default_language;
const fallback_locale = window.fallback_locale;
const messages = window.messages;

Vue.prototype.trans = new Lang( { messages, locale: default_locale, fallback: fallback_locale } );
```

```
// Example.vue

```

A note about json files
-----------------------

[](#a-note-about-json-files)

Laravel 5.4+ allows localization to be strutured [using a single `.json` file for each language](https://laravel.com/docs/5.7/localization#using-translation-strings-as-keys), in order to use the strings inside the provided json file you must prepend the `__JSON__` key

```
// Assuming that es.json exists and it is the default locale in your app
{
   "I love programming": "Me encanta programar"
}
```

```
// Example.vue

```

Routing
-------

[](#routing)

This package exposes one route `http://localhost/js/localization.js` by default but you can change the prefix to anything you whish in config file.

You can also have a nice route name for blade templates or any other route calls, it's `route('assets.lang')` by default but it's customizable by config/environment file.

Proposals, comments, feedback
-----------------------------

[](#proposals-comments-feedback)

Everything of this is highly welcome and appreciated

To-Do
-----

[](#to-do)

- Create exclude configuration so not files/directories are collected

Anything else you can think of please leave me comments, mail me, create issue, whatever you prefer.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 Bus Factor1

Top contributor holds 75.3% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/540320d4804f7add05f4a82824eda7ad73055963bed3e3b5277a6b61a216cce5?d=identicon)[memdev](/maintainers/memdev)

---

Top Contributors

[![kg-bot](https://avatars.githubusercontent.com/u/5282920?v=4)](https://github.com/kg-bot "kg-bot (119 commits)")[![tomhatzer](https://avatars.githubusercontent.com/u/3952168?v=4)](https://github.com/tomhatzer "tomhatzer (13 commits)")[![ridaamirini](https://avatars.githubusercontent.com/u/14841555?v=4)](https://github.com/ridaamirini "ridaamirini (4 commits)")[![Patrick-De-Caluwe](https://avatars.githubusercontent.com/u/50628036?v=4)](https://github.com/Patrick-De-Caluwe "Patrick-De-Caluwe (3 commits)")[![ollieread](https://avatars.githubusercontent.com/u/469515?v=4)](https://github.com/ollieread "ollieread (2 commits)")[![meduzen](https://avatars.githubusercontent.com/u/9340937?v=4)](https://github.com/meduzen "meduzen (2 commits)")[![Generation4](https://avatars.githubusercontent.com/u/7221444?v=4)](https://github.com/Generation4 "Generation4 (2 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (2 commits)")[![ludo237](https://avatars.githubusercontent.com/u/921500?v=4)](https://github.com/ludo237 "ludo237 (2 commits)")[![MartinP7r](https://avatars.githubusercontent.com/u/2669027?v=4)](https://github.com/MartinP7r "MartinP7r (1 commits)")[![esseremmerik](https://avatars.githubusercontent.com/u/3390371?v=4)](https://github.com/esseremmerik "esseremmerik (1 commits)")[![jcalonso](https://avatars.githubusercontent.com/u/664474?v=4)](https://github.com/jcalonso "jcalonso (1 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")[![lsmith77](https://avatars.githubusercontent.com/u/300279?v=4)](https://github.com/lsmith77 "lsmith77 (1 commits)")[![manuelteuber](https://avatars.githubusercontent.com/u/655280?v=4)](https://github.com/manuelteuber "manuelteuber (1 commits)")[![ciamarro](https://avatars.githubusercontent.com/u/2736722?v=4)](https://github.com/ciamarro "ciamarro (1 commits)")[![maxacarvalho](https://avatars.githubusercontent.com/u/45166618?v=4)](https://github.com/maxacarvalho "maxacarvalho (1 commits)")[![robertgarrigos](https://avatars.githubusercontent.com/u/105581?v=4)](https://github.com/robertgarrigos "robertgarrigos (1 commits)")

### Embed Badge

![Health badge](/badges/memdev-laravel-localization-to-vue/health.svg)

```
[![Health](https://phpackages.com/badges/memdev-laravel-localization-to-vue/health.svg)](https://phpackages.com/packages/memdev-laravel-localization-to-vue)
```

PHPackages © 2026

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