PHPackages                             empuxa/laravel-locale-via-api - 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. empuxa/laravel-locale-via-api

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

empuxa/laravel-locale-via-api
=============================

Easily provide your lang files via API.

v3.1.0(2mo ago)09.4k↓100%[1 PRs](https://github.com/empuxa/laravel-locale-via-api/pulls)MITPHPPHP ^8.1CI passing

Since Dec 11Pushed 2mo agoCompare

[ Source](https://github.com/empuxa/laravel-locale-via-api)[ Packagist](https://packagist.org/packages/empuxa/laravel-locale-via-api)[ Docs](https://github.com/empuxa/laravel-locale-via-api)[ GitHub Sponsors](https://github.com/marcoraddatz)[ RSS](/packages/empuxa-laravel-locale-via-api/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (6)Versions (16)Used By (0)

Laravel Locale Via API
======================

[](#laravel-locale-via-api)

[![Latest Version on Packagist](https://camo.githubusercontent.com/6dea5f2143022b65a304e7e7bcdc02687e0442783e9d4c576383c13d7aeec768/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656d707578612f6c61726176656c2d6c6f63616c652d7669612d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/empuxa/laravel-locale-via-api)[![Tests](https://camo.githubusercontent.com/427e84d7906ad3e021236718b13ecb0a40905e95ee764e13b38b558a57f9552f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656d707578612f6c61726176656c2d6c6f63616c652d7669612d6170692f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/empuxa/laravel-locale-via-api/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/8a0292c4ffd038c1576503c86dc9366d5aa29db9819594542e5d28b46a2bf4f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656d707578612f6c61726176656c2d6c6f63616c652d7669612d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/empuxa/laravel-locale-via-api)

[![Banner](https://camo.githubusercontent.com/ac63475b31a682119c7cb6d7f466846b35a50f392582bbe2f436838860704977/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532304c6f63616c652532305669612532304150492e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d656d707578612532466c61726176656c2d6c6f63616c652d7669612d617069267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)](https://camo.githubusercontent.com/ac63475b31a682119c7cb6d7f466846b35a50f392582bbe2f436838860704977/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532304c6f63616c652532305669612532304150492e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d656d707578612532466c61726176656c2d6c6f63616c652d7669612d617069267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)

This package lets you share your local translations via API, so that any app can use them. To do so, it converts your PHP lang files to JSON.

Requirements
------------

[](#requirements)

1. You must provide your lang files within folders, such as `lang/en` or `lang/de`.
2. The lang files must be in PHP format, such as `lang/en/validation.php`.
3. Must secure the API routes and its patterns on your own.

Installation
------------

[](#installation)

This package requires Laravel 9.33+. You can install the package via composer:

```
composer require empuxa/laravel-locale-via-api
```

Afterward, you might want to copy the vendor files:

```
php artisan vendor:publish --provider="Empuxa\LocaleViaApi\LocaleViaApiServiceProvider"
```

Remember to also update the config file `config/locale-via-api.php` to your needs!

Usage
-----

[](#usage)

This package provides two controllers to access your translations via API. You must add them to your `routes/api.php` file manually.

### `Empuxa\LocaleViaApi\Http\Controllers\ListLocalesController`

[](#empuxalocaleviaapihttpcontrollerslistlocalescontroller)

With this controller, you can list any locale that is available in your app. For security reasons, it only returns the array from your config and doesn't read the actual files.

```
Route::get('/locales', ListLocalesController::class);
```

By adding `?flatten=true` to the URL, you can get a flat array of all available locales. You can also change the default behavior in the config file.

#### Non-flattened response

[](#non-flattened-response)

```
{
    "data": {
        "api": {
            "error": {
                "401": "Unauthenticated.",
                "403": "Forbidden.",
                "404": "Not Found.",
                "422": "Unprocessable Entity."
            }
        }
    }
}
```

#### Flattened response

[](#flattened-response)

```
{
    "data": {
        "api.error.401": "Unauthenticated.",
        "api.error.403": "Forbidden.",
        "api.error.404": "Not Found.",
        "api.error.422": "Unprocessable Entity."
    }
}
```

### `Empuxa\LocaleViaApi\Http\Controllers\GetLocaleController`

[](#empuxalocaleviaapihttpcontrollersgetlocalecontroller)

This controller returns the contents of a locale directory as JSON. If the directory does not exist, it will return an error 404.

```
Route::get('/locales/{locale}', GetLocaleController::class);
```

Security
--------

[](#security)

Since this package reads your lang files (and could theoretically read any other files as well), it is important to protect your API routes. **Make sure that you only share the locales that you want to share.**Add route pattern to do so.

### Security Best Practices

[](#security-best-practices)

1. **Protect your routes** - Always use authentication middleware on the locale API routes:

    ```
    Route::middleware('auth:sanctum')->group(function () {
        Route::get('/locales', ListLocalesController::class);
        Route::get('/locales/{locale}', GetLocaleController::class);
    });
    ```
2. **Restrict locale patterns** - Use route constraints to limit valid locale values:

    ```
    Route::get('/locales/{locale}', GetLocaleController::class)
        ->where('locale', '[a-z]{2}');
    ```
3. **Protect your lang directory** - This package uses `File::getRequire()` which executes PHP code from locale files. Never allow untrusted users to write to your `lang/` directory.
4. **Use vendor safelist** - If you enable `load_vendor_files`, consider using the `vendor_safelist` config option to restrict which vendor packages are exposed.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Marco Raddatz](https://github.com/marcoraddatz)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance86

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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 ~115 days

Recently: every ~163 days

Total

8

Last Release

74d ago

Major Versions

v1.0.1 → v2.0.02024-05-16

v2.3.0 → v3.0.02026-02-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/9a2715a7b4e17b0ed07d23b300474f34d97d7abafbb602ec399f352a62f2e527?d=identicon)[marcoraddatz](/maintainers/marcoraddatz)

---

Top Contributors

[![marcoraddatz](https://avatars.githubusercontent.com/u/248815?v=4)](https://github.com/marcoraddatz "marcoraddatz (22 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (14 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")

---

Tags

i18nempuxamarcoraddatz

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/empuxa-laravel-locale-via-api/health.svg)

```
[![Health](https://phpackages.com/badges/empuxa-laravel-locale-via-api/health.svg)](https://phpackages.com/packages/empuxa-laravel-locale-via-api)
```

###  Alternatives

[symfony/string

Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way

1.8k724.1M827](/packages/symfony-string)[symfony/intl

Provides access to the localization data of the ICU library

2.6k199.8M1.1k](/packages/symfony-intl)[gettext/gettext

PHP gettext manager

70530.2M102](/packages/gettext-gettext)[gettext/languages

gettext languages with plural rules

7530.3M11](/packages/gettext-languages)[smousss/laravel-globalize

Make Laravel projects translatable in a matter of seconds!

2266.3k](/packages/smousss-laravel-globalize)[inpsyde/multilingual-press

Simply THE multisite-based free open source plugin for your multilingual websites.

2414.0k1](/packages/inpsyde-multilingual-press)

PHPackages © 2026

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