Download the PHP package tyler36/localization without Composer
On this page you can find all versions of the php package tyler36/localization. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tyler36/localization
More information about tyler36/localization
Files in tyler36/localization
Informations about the package localization
Introduction
This package is designed to simplify multi-locale applications. Simply add the required middleware and update your configuration.
Installation
-
Install package
-
Publish configuration Run the command below to publish the configuration file
-
Add supported languages By default, only the current app locale is deemed valid. You can add additional languages to configuration file (). Can't see the file? Perhaps you forgot to publish it; see the above step. For a list of internationally recognized language codes, see https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes.
- Apply middleware Add the desired middle to the file in the required location. For more details, see the Laravel documentation (https://laravel.com/docs/master/middleware#registering-middleware)
Middleware
Option 1: Header request
This middleware uses a request header to set the locale. By default, the query string is set to but can be changed through the config file. It's ideal for making request via javascript.
-
Register
- Set the header in via vanilla javascript or preferred javascript framework. For example, you can apply the header to all request with the following:
Now, when you send a request to the endpoint Laravel will update the locale to match the setting, assuming it is configured as 'valid'.
Option 2: Query String
This middleware is designed to use a query string.
-
Register
- Add the query string to a URL. By default, the query string is set to but can be changed through the config file.
Option 3: Member preference
This middleware uses an attribute on the User model to set the locale. When a member is logged in, it check their saved locale and applies it.
-
Register
- Create the attribute on User models By default, the query string is set to but can be changed through the config file.
Option 4: Session
This middleware looks for a value in Laravel session.
-
Register
- Create a route that saves the to the session By default, the is set to but can be changed through the config file.
or you could use the included controller by updating your route file