Download the PHP package akaunting/language without Composer
On this page you can find all versions of the php package akaunting/language. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package language
Language switcher package for Laravel
This package allows switching locale easily on Laravel projects. It's so simple to use, once it's installed, your App locale will change only by passing routes into SetLanguage middleware.
Top features:
- Change automatically app locale depending on user browser configuration
- Language flags built-in for easy implementation
- Get language name like 'English' or 'Español' from codes such as 'en' or 'es'
- Option to choose short (en) or long (en-GB) language code
- Store locale on users table
- Restrict users to set languages you don't have translations
- Helper functions for clean, simple and easy to read API
- Supports Carbon and Date packages
Getting Started
1. Install
Run the following command:
2. Register (for Laravel < 5.5)
Register the service provider in config/app.php
Add alias if you want to use the facade.
3. Publish
Publish config, migration and blade files.
4. Migrate
Add locale column to users table:
5. Configure
Default values can be modified also on config/language.php
Keys
- route: Makes route available
- carbon: Sets briannesbitt/carbon translator language
- date: Sets jenssegers/date translator language
- home: Make home route available
- auto: Sets language automatically depending on user's browser config
- prefix: Prefix of routes URI to set locale
- middleware: default middleware to set locale
- controller: default controller to handle locale
- flags: Settings such as width, class etc for flags
- mode: The language code and name mode
- allowed: Allowed language codes
- all: Available language names and codes
Usage
Middleware
All routes in which you want to set language should be under the language
middleware to set at each request to App locale.
URL
- Via URL with return home: /languages/{locale}/home
- Via URL with return back: /languages/{locale}/back
Tip: /languages prefix can be changed from
Methods
language()->allowed()
Returns an array with for all allowed languages of config. Example usage on blade:
language()->flags()
Returns an output with flags for all allowed languages of config. Output can be changed from folder
language()->flag()
Returns the flag of the current locale. Output can be changed from folder
language()->names($codes = null)
Get an array like from an array of only $codes.
language()->codes($langs = null)
Get an array like from an array of only $langs.
language()->back($code)
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:
language()->home($code)
Returns the URL to set language and return to home:
Also if you prefer to use directly route() function you can use it as following code:
language()->getName($code = 'default')
Returns the language name of if specified or the current language set if not.
Tip: Use app()->getLocale() to get the current locale
language()->getCode($name = 'default')
Returns the language code of if specified or the current language set if not.
Changelog
Please see Releases for more information what has changed recently.
Contributing
Pull requests are more than welcome. You must follow the PSR coding standards.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Denis Duliçi
- All Contributors
License
The MIT License (MIT). Please see LICENSE for more information.