{"id":22823210,"url":"https://github.com/benconstable/laravel-localize-middleware","last_synced_at":"2025-05-07T15:06:49.724Z","repository":{"id":62493105,"uuid":"56628445","full_name":"BenConstable/laravel-localize-middleware","owner":"BenConstable","description":"Configurable localization middleware for your Laravel \u003e=5.1 application","archived":false,"fork":false,"pushed_at":"2020-03-05T13:13:53.000Z","size":38,"stargazers_count":92,"open_issues_count":5,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T15:06:41.367Z","etag":null,"topics":["laravel","localisation","localization","middleware"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BenConstable.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-19T20:10:43.000Z","updated_at":"2024-07-09T09:44:06.000Z","dependencies_parsed_at":"2022-11-02T11:17:48.193Z","dependency_job_id":null,"html_url":"https://github.com/BenConstable/laravel-localize-middleware","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenConstable%2Flaravel-localize-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenConstable%2Flaravel-localize-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenConstable%2Flaravel-localize-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenConstable%2Flaravel-localize-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BenConstable","download_url":"https://codeload.github.com/BenConstable/laravel-localize-middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252902614,"owners_count":21822261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","localisation","localization","middleware"],"created_at":"2024-12-12T16:15:48.229Z","updated_at":"2025-05-07T15:06:49.679Z","avatar_url":"https://github.com/BenConstable.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Localize Middleware\n\n\u003e Configurable localization middleware for your Laravel \u003e=5.1 application.\n\n[![Build Status](https://travis-ci.org/BenConstable/laravel-localize-middleware.svg?branch=master)](https://travis-ci.org/BenConstable/laravel-localize-middleware)\n[![Latest Stable Version](https://poser.pugx.org/benconstable/laravel-localize-middleware/v/stable)](https://packagist.org/packages/benconstable/laravel-localize-middleware)\n[![License](https://poser.pugx.org/benconstable/laravel-localize-middleware/license)](https://packagist.org/packages/benconstable/laravel-localize-middleware)\n\nThis package provides a simple set of configuration and middleware to allow you\nto automatically set your application's locale using the current request. You can\nset the locale from a request parameter, header, the current host, a cookie or\nsession data.\n\n## Installation\n\nInstall the package via Composer:\n\n```\n$ composer require benconstable/laravel-localize-middleware\n```\n\nNext, add the package's service provider to your `config/app.php`:\n\n```php\n// config/app.php\n\n'providers' =\u003e [\n    BenConstable\\Localize\\LocalizeServiceProvider::class\n]\n```\n\nand then you'll just need to publish the package's configuration:\n\n```\n$ php artisan vendor:publish --provider=\"BenConstable\\Localize\\LocalizeServiceProvider\"\n```\n\nwhich will create `config/localize-middleware.php`.\n\n## Usage\n\nOut-of-the-box, the package is configured to set the application locale using a\nrequest parameter called `locale` (see the next section for more info). To enable\nthis functionality, just [register the provided middleware](https://laravel.com/docs/5.4/middleware#registering-middleware) in your `app/Http/Kernel.php` class:\n\n```php\n// app/Http/Kernel.php\n\nprotected $middleware = [\n    \\BenConstable\\Localize\\Http\\Middleware\\Localize::class\n];\n```\n\nIt's recommended to set this middleware globally and early in the stack, but you're\nfree to register it in whatever way that suits your needs.\n\n### Configuration\n\nConfiguration can be found at `config/localize-middleware.php`. From there, you\ncan configure which localization determiner you'd like to use in your application\nand set options for it. You simply have to change the `driver` option.\n\nThe list of available determiners is shown below.\n\n### Determining the locale from a request parameter\n\n**Driver name:** `parameter`\n\nThe default determiner sets the application locale from a request parameter\ncalled `locale`. You can change this using the `parameter` configuration option.\n\nThe parameter will be discovered in the query string or request body.\n\n### Determining the locale from a request header\n\n**Driver name:** `header`\n\nThis determiner sets the application locale from a request header, which defaults\nto `Accept-Language`. You can change this using the `header` configuration option.\n\n*Aside:* For information on using `Accept-Language` to determine the locale,\nsee [this info from the W3C](https://www.w3.org/International/questions/qa-accept-lang-locales).\n\n### Determining the locale using the current host\n\n**Driver name:** `host`\n\nThis determiner sets a different application locale depending on the current host.\nYou'll need to set a map of your application's locales to hosts using the `hosts`\nconfiguration option.\n\n### Determining the locale from a cookie\n\n**Driver name:** `cookie`\n\nThis determiner sets the application locale from a cookie called `locale`. You can\nchange this using the `cookie` configuration option.\n\n### Determining the locale from the session\n\n**Driver name:** `session`\n\nThis determiner sets the application locale from a session value called `locale`.\nYou can change this using the `session` configuration option.\n\n### Using multiple determiners\n\nSometimes it might be useful to try and determine the locale from more than one\nsource. If you'd like to do this, just set the `driver` configuration option to an\narray of other driver names. For example:\n\n```php\n'driver' =\u003e [\n    'cookie',\n    'parameter'\n]\n```\n\nThe locale will then be deteremined from whichever determiner first provides a\nsuccessful match, so make sure you add the drivers in the correct order (earliest\nin the array will be used first).\n\n### Determining the locale outside of middleware\n\nYou don't have to use the provided middleware if you don't want to. You can\ninstead write your own, or avoid using middleware entirely.\n\nTo determine the locale in your own code, first register an alias for the provided\nfacade (which is actually a reference to `BenConstable\\Localize\\DeterminerManager`, if\nyou want to inject it).\n\n```php\n// config/app.php\n\n'aliases' =\u003e [\n    'Localizer' =\u003e BenConstable\\Localize\\DeterminerFacade::class\n]\n```\n\nThen, you can just do:\n\n```php\n$locale = Localizer::determineLocale($request);\n```\n\nto determine the locale and do with it what you like.\n\n## Contributing\n\nSee [CONTRIBUTING.md](https://github.com/BenConstable/laravel-localize-middleware/blob/master/CONTRIBUTING.md).\n\n## Other Localization Projects\n\nHere are some other Laravel localization projects that might be useful to you:\n\n* [mcamara/laravel-localization](https://github.com/mcamara/laravel-localization)\n* [Waavi/translation](https://github.com/Waavi/translation)\n* [caouecs/Laravel-lang](https://github.com/caouecs/Laravel-lang)\n\n## License\n\nMIT \u0026copy; Ben Constable 2017. See [LICENSE](https://github.com/BenConstable/laravel-localize-middleware/blob/master/LICENSE) for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenconstable%2Flaravel-localize-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenconstable%2Flaravel-localize-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenconstable%2Flaravel-localize-middleware/lists"}