PHPackages                             cosnavel/laravel-query-localization - 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. cosnavel/laravel-query-localization

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

cosnavel/laravel-query-localization
===================================

Query String Localization Package for Laravel

0.3.0(4y ago)508.2k2MITPHPPHP ^8.0

Since Aug 6Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Cosnavel/laravel-query-localization)[ Packagist](https://packagist.org/packages/cosnavel/laravel-query-localization)[ Docs](https://github.com/cosnavel/laravel-query-localization)[ GitHub Sponsors](https://github.com/Cosnavel)[ RSS](/packages/cosnavel-laravel-query-localization/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (12)Versions (6)Used By (0)

[![laravel-package_2](https://user-images.githubusercontent.com/42392570/128426801-fe9ad4cc-1063-4fb3-9e0e-62a5e9dfaaf2.png)](https://user-images.githubusercontent.com/42392570/128426801-fe9ad4cc-1063-4fb3-9e0e-62a5e9dfaaf2.png)

Query String Localization Package for Laravel
=============================================

[](#query-string-localization-package-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5e618ca8c3531dcde71c651a9b6cebc429d650696951ff86ea968469a8b06c25/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f736e6176656c2f6c61726176656c2d71756572792d6c6f63616c697a6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cosnavel/laravel-query-localization)[![GitHub Tests Action Status](https://camo.githubusercontent.com/bf59bfd962f14d285d24af998e0915bfd89098a343a4a495f4f003aeffa23382/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f636f736e6176656c2f6c61726176656c2d71756572792d6c6f63616c697a6174696f6e2f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/cosnavel/laravel-query-localization/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/70564637132c647c333958448fe6532f239fb1b668dd69c446a5630afbf33a7a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f636f736e6176656c2f6c61726176656c2d71756572792d6c6f63616c697a6174696f6e2f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/cosnavel/laravel-query-localization/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/2610ab947bd8fee05009c542159242abb1389de7472223e11bbe81789b764bfd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f736e6176656c2f6c61726176656c2d71756572792d6c6f63616c697a6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cosnavel/laravel-query-localization)

---

Use this package to localize your laravel application via query strings easily.

### Features:

[](#features)

- Localization based on a query string.
- Includes a Livewire language selector component.
- Optionally stores the user language preference to the user's table and apply it for every session.

---

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

[](#installation)

To get started, require the package via composer:

```
composer require cosnavel/laravel-query-localization
```

### Config File

[](#config-file)

You can publish the config file with:

```
php artisan vendor:publish --provider="Cosnavel\LaravelQueryLocalization\LaravelQueryLocalizationServiceProvider" --tag="laravel-query-localization-config"
```

After publishing, *config query-localization.php* will be created.

The configuration options are:

- **supportedLocales** Languages of your app (Default: English &amp; German).
- **useAcceptLanguageHeader** If true, then automatically detect language from browser.
- **useUserLanguagePreference** If true, save the language preference of an authenticated user in the database and apply the preference on each session

Usage
-----

[](#usage)

### Register Middleware

[](#register-middleware)

To get started, register the LocaleFromQuery middleware for the Route Group that needs to be localized.

```
// routes/web.php

Route::middleware(LocaleFromQuery::class)->group(function () {
    Route::view('/', 'welcome');
});
```

### User Language Preference

[](#user-language-preference)

If you want to save the language preference to the users table:

- publish the config file
- enable `useLanguageUserPreference` in the config file
- publish and run the migrations

You can publish and run the migrations with:

```
php artisan vendor:publish --provider="Cosnavel\LaravelQueryLocalization\LaravelQueryLocalizationServiceProvider" --tag="query-localization-migrations"
php artisan migrate
```

- if you want to use mass assignment for the `language_preference` field in the users table make the field fillable in the user model

Helpers
-------

[](#helpers)

### Get Supported Locales

[](#get-supported-locales)

Return all supported locales and their properties as an array.

```
Cosnavel\LaravelQueryLocalization\Facades\LaravelQueryLocalization::getSupportedLocales();
```

### Get Current Locale

[](#get-current-locale)

Return the key of the current locale.

- Return the current locale from the session
- if none found, it negotiates locale from acceptLanguageHeaders.
- when acceptLanguageHeaders option is disabled, and no value is available in the session, use the applications default locale

```
Cosnavel\LaravelQueryLocalization\Facades\LaravelQueryLocalization::getCurrentLocale();
```

### Determine Valid Locales

[](#determine-valid-locales)

Checks if the passed locale is a supportedLocale (check the config to add your needed locales). If it is not, the returned locale is the application's default locale.

```
Cosnavel\LaravelQueryLocalization\Facades\LaravelQueryLocalization::determineValidLanguage('en');
```

### Set Locale

[](#set-locale)

Set locale programmatically. Internally the passed locale gets determined if it's a valid locale.

```
Cosnavel\LaravelQueryLocalization\Facades\LaravelQueryLocalization::setLocale('en');
```

### Set User Language Preference

[](#set-user-language-preference)

Set an authed user's language preference. The passed language will also be checked for availability.

```
Cosnavel\LaravelQueryLocalization\Facades\LaravelQueryLocalization::setUserLanguagePreference('en');
```

Language Selector
-----------------

[](#language-selector)

If you're supporting multiple locales in your project, you will probably want to provide the users with a way to change the language.

Included in this package is a language selector. The Language Selector is built with Tailwind, Alpine &amp; Livewire.

    CleanShot.2021-08-06.at.11.32.42.mp4    ### Alpine

[](#alpine)

The Language Picker requires Alpine. You can use the official CDN to quickly include Alpine:

```

```

### Usage

[](#usage-1)

Just include the Livewire Component in your blade view. All available locales from your config will be used.

```
@livewire('language-selector')
```

When *useUserLanguagePreference* is enabled, the language preference of an authenticated user will be set.

If you don't want to use Tailwind or want to customize the language picker, I recommend that you publish the component the markup as you like.

```
php artisan vendor:publish --provider="Cosnavel\LaravelQueryLocalization\LaravelQueryLocalizationServiceProvider" --tag="query-localization-views"
```

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Cosnavel](https://github.com/Cosnavel)
- [Rheamars](https://github.com/Rheamars)
- [Lotti](https://twitter.com/CharlotteZaspel) Thanks for the artwork
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.4% 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 ~46 days

Total

5

Last Release

1553d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/42392570?v=4)[Niclas Kahlmeier](/maintainers/Cosnavel)[@Cosnavel](https://github.com/Cosnavel)

---

Top Contributors

[![Cosnavel](https://avatars.githubusercontent.com/u/42392570?v=4)](https://github.com/Cosnavel "Cosnavel (62 commits)")[![RheaMars](https://avatars.githubusercontent.com/u/75316896?v=4)](https://github.com/RheaMars "RheaMars (2 commits)")[![Lednerb](https://avatars.githubusercontent.com/u/2056876?v=4)](https://github.com/Lednerb "Lednerb (1 commits)")

---

Tags

hacktoberfesti18nlaravellocalizationphplaravelCosnavellaravel-query-localization

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/cosnavel-laravel-query-localization/health.svg)

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

###  Alternatives

[askdkc/breezejp

Laravel Starter Kit (Livewire+Breeze+Laravel UI+Jetstream)や標準のバリデーションメッセージを全て一瞬で日本語化し、言語切替機能も提供するパッケージです / This package provides all-in-one Japanese translation for Laravel StarterKit (Livewire StarterKit, Breeze, Laravel UI and Jetstream) packages and validation messages with language switching feature.

590244.8k1](/packages/askdkc-breezejp)[statikbe/laravel-filament-chained-translation-manager

A translation manager tool for Laravel Filament, that makes use of the Laravel Chained Translator.

92108.7k](/packages/statikbe-laravel-filament-chained-translation-manager)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[elegantly/laravel-translator

All on one translations management for Laravel

6216.9k](/packages/elegantly-laravel-translator)[fidum/laravel-translation-linter

Commands to help you keep your laravel translations organized.

2476.3k](/packages/fidum-laravel-translation-linter)[andrewdwallo/transmatic

Automate and streamline real-time text translations in your Laravel applications

5511.6k](/packages/andrewdwallo-transmatic)

PHPackages © 2026

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