Download the PHP package cosnavel/laravel-query-localization without Composer
On this page you can find all versions of the php package cosnavel/laravel-query-localization. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cosnavel/laravel-query-localization
More information about cosnavel/laravel-query-localization
Files in cosnavel/laravel-query-localization
Package laravel-query-localization
Short Description Query String Localization Package for Laravel
License MIT
Homepage https://github.com/cosnavel/laravel-query-localization
Informations about the package laravel-query-localization
Query String Localization Package for Laravel
Use this package to localize your laravel application via query strings easily.
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
To get started, require the package via composer:
Config File
You can publish the config file with:
After publishing, config query-localization.php will be created.
The configuration options are:
-
supportedLocales Languages of your app (Default: English & 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
Register Middleware
To get started, register the LocaleFromQuery middleware for the Route Group that needs to be localized.
User Language Preference
If you want to save the language preference to the users table:
- publish the config file
- enable in the config file
- publish and run the migrations
You can publish and run the migrations with:
- if you want to use mass assignment for the field in the users table make the field fillable in the user model
Helpers
Get Supported Locales
Return all supported locales and their properties as an array.
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
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.
Set Locale
Set locale programmatically. Internally the passed locale gets determined if it's a valid locale.
Set User Language Preference
Set an authed user's language preference. The passed language will also be checked for availability.
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 & Livewire.
Alpine
The Language Picker requires Alpine. You can use the official CDN to quickly include Alpine:
Usage
Just include the Livewire Component in your blade view. All available locales from your config will be used.
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.
Testing
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-query-localization with dependencies
illuminate/contracts Version ^8.73 || ^9.0
spatie/laravel-package-tools Version ^1.11