Download the PHP package zymawy/localizer without Composer
On this page you can find all versions of the php package zymawy/localizer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zymawy/localizer
More information about zymawy/localizer
Files in zymawy/localizer
Package localizer
Short Description Pakcage to change easily default locale in laravel 5.4
License MIT
Informations about the package localizer
Localizer
What is Localizer?
Localizer is a laravel package to change easily locale on laravel projects.
It's so simple to use, once it's installed, your App locale will change only by passing routes into localizer middleare.
Top features:
- Change automatically app locale depending on user browser configuration
- Get language like 'Spanish' or 'English' from codes such as 'es' or 'en'.
- Store on users database table the user locale preference
- Restrict users to set languages you don't have translations
Getting Started
1. Install it with composer
Running the command below:
2. Register service provider
Register the localizer service provider on config/app.php
.
Remind to add alias to use Localizer functions comfortably.
3. Publish config
It will publish config file.
Running the command below:
3.1 Publish languages
Also you can publish your languages to modify or add.
4. Migrate
Publish migrations:
Running the command below:
5. Configure defalt values
Default values can be modified also on config/localizer.php
.
Keys
- routes: Makes routes available.
- carbon: Sets carbon translator language.
- homeRoute: Make home route available.
- set_auto_lang: Sets language automatically depending on user's browser config
- default_lang: Default language if set_auto_lang is false or user is attempting to set an unallowed language
- prefix: Prefix of routes URI to set locale,
- allowed_langs: All allowed languages,
- middleware: default middleware to set locale,
Using Localizer
Middleware
All routes in which you want to set language should be under the localizer's middleware to set at each request de App locale.
Changing languages
- Via URL with return home: /lang/set/{locale}/home
- Via URL with return back: /lang/set/{locale}
Tip: /lang prefix will be changed on config
Example languages view
Following there are a little code snippet of a view to select and set languages:
API
Localizer::allowedLanguages()
Returns an array with [$code => $language] for all allowed languages of config.
Localizer::addNames($codes)
Get an array like [$code => $language] from an array of only $codes.
Localizer::addCodes($lang)
Get an array like [$language => $code] from an array of only $langs.
Localizer::setRoute($code)
Used for modals or dropdowns
Returns the url to set up language and return back.
Also if you prefer to use directly route() function you can use it as following code:
Localizer::setRouteHome($code)
Used for language selection views
Returns the url to set language and return '/' url('/')
Also if you prefer to use directly route() function you can use it as following code:
Localizer::getLanguage($code = App::getLocale())
Returns the language name of $code if specified or the current language setted if not.
Tip: Use App::getLocale() to get the current locale
All versions of localizer with dependencies
laravel/framework Version 5.*|^6.0|^7.0
consoletvs/identify Version 1.*