{"id":26085272,"url":"https://github.com/codezero-be/laravel-localizer","last_synced_at":"2025-06-13T04:03:12.035Z","repository":{"id":50253336,"uuid":"127637264","full_name":"codezero-be/laravel-localizer","owner":"codezero-be","description":"⭐️ Automatically detect and set an app locale that matches your visitor's preference.","archived":false,"fork":false,"pushed_at":"2024-03-11T13:45:59.000Z","size":98,"stargazers_count":46,"open_issues_count":1,"forks_count":8,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-24T17:58:22.811Z","etag":null,"topics":["browser","cookie","country","detect","language","laravel","locale","localization","php","session"],"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/codezero-be.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"ivanvermeyen","custom":"https://paypal.me/ivanvermeyen"}},"created_at":"2018-04-01T14:35:54.000Z","updated_at":"2024-04-19T18:47:30.000Z","dependencies_parsed_at":"2024-06-18T17:01:07.351Z","dependency_job_id":null,"html_url":"https://github.com/codezero-be/laravel-localizer","commit_stats":{"total_commits":55,"total_committers":5,"mean_commits":11.0,"dds":"0.12727272727272732","last_synced_commit":"7c03cc0aea0a0047a2d40e4dc39547f4a198555e"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codezero-be%2Flaravel-localizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codezero-be%2Flaravel-localizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codezero-be%2Flaravel-localizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codezero-be%2Flaravel-localizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codezero-be","download_url":"https://codeload.github.com/codezero-be/laravel-localizer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244047645,"owners_count":20389206,"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":["browser","cookie","country","detect","language","laravel","locale","localization","php","session"],"created_at":"2025-03-09T05:58:09.467Z","updated_at":"2025-03-17T14:18:16.260Z","avatar_url":"https://github.com/codezero-be.png","language":"PHP","funding_links":["https://ko-fi.com/ivanvermeyen","https://paypal.me/ivanvermeyen","https://ko-fi.com/R6R3UQ8V"],"categories":[],"sub_categories":[],"readme":"# Laravel Localizer\n\n[![GitHub release](https://img.shields.io/github/release/codezero-be/laravel-localizer.svg?style=flat-square)](https://github.com/codezero-be/laravel-localizer/releases)\n[![Laravel](https://img.shields.io/badge/laravel-11-red?style=flat-square\u0026logo=laravel\u0026logoColor=white)](https://laravel.com)\n[![License](https://img.shields.io/packagist/l/codezero/laravel-localizer.svg?style=flat-square)](LICENSE.md)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/codezero-be/laravel-localizer/run-tests.yml?style=flat-square\u0026logo=github\u0026logoColor=white\u0026label=tests)](https://github.com/codezero-be/laravel-localizer/actions)\n[![Code Coverage](https://img.shields.io/codacy/coverage/ad6fcea152b449d380a187a375d0f7d7/master?style=flat-square)](https://app.codacy.com/gh/codezero-be/laravel-localizer)\n[![Code Quality](https://img.shields.io/codacy/grade/ad6fcea152b449d380a187a375d0f7d7/master?style=flat-square)](https://app.codacy.com/gh/codezero-be/laravel-localizer)\n[![Total Downloads](https://img.shields.io/packagist/dt/codezero/laravel-localizer.svg?style=flat-square)](https://packagist.org/packages/codezero/laravel-localizer)\n\n[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/R6R3UQ8V)\n\nAutomatically detect and set an app locale that matches your visitor's preference.\n\n- Define your supported locales and match your visitor's preference\n- Uses the most common locale [detectors](#-detectors) by default\n- Uses the most common locale [stores](#-stores) by default\n- Easily create and add your own detectors and stores\n\n## ✅ Requirements\n\n- PHP \u003e= 8.1\n- Laravel \u003e= 10.0\n\n## ⬆ Upgrade\n\nUpgrading to a new major version?\nCheck our [upgrade guide](UPGRADE.md) for instructions.\n\n## 📦 Install\n\nInstall this package with Composer:\n\n```bash\ncomposer require codezero/laravel-localizer\n```\n\nLaravel will automatically register the ServiceProvider.\n\n## 🧩 Add Middleware\n\nBy default, the app locale will always be what you configured in `config/app.php`.\nTo automatically update the app locale, you need to register the middleware in the `web` middleware group.\nMake sure to add it after `StartSession` and before `SubstituteBindings`.\n\nThe order of the middleware is important if you are using localized route keys (translated slugs)!\nThe session needs to be active when setting the locale, and the locale needs to be set when substituting the route bindings.\n\n### Laravel 11 and newer:\n\nAdd the middleware to the `web` middleware group in `bootstrap/app.php`.\n\n```php\n// bootstrap/app.php\n-\u003ewithMiddleware(function (Middleware $middleware) {\n    $middleware-\u003eweb(remove: [\n        \\Illuminate\\Routing\\Middleware\\SubstituteBindings::class,\n    ]);\n    $middleware-\u003eweb(append: [\n        \\CodeZero\\Localizer\\Middleware\\SetLocale::class,\n        \\Illuminate\\Routing\\Middleware\\SubstituteBindings::class,\n    ]);\n})\n```\n\n### Laravel 10:\n\nAdd the middleware to the `web` middleware group in `app/Http/Kernel.php`.\n\n```php\n// app/Http/Kernel.php\nprotected $middlewareGroups = [\n    'web' =\u003e [\n        //...\n        \\Illuminate\\Session\\Middleware\\StartSession::class, // \u003c= after this\n        //...\n        \\CodeZero\\Localizer\\Middleware\\SetLocale::class,\n        \\Illuminate\\Routing\\Middleware\\SubstituteBindings::class, // \u003c= before this\n    ],\n];\n```\n\n## ⚙ Configure\n\n### Publish Configuration File\n\n```bash\nphp artisan vendor:publish --provider=\"CodeZero\\Localizer\\LocalizerServiceProvider\" --tag=\"config\"\n```\n\nYou will now find a `localizer.php` file in the `config` folder.\n\n### Configure Supported Locales\n\nAdd any locales you wish to support to your published `config/localizer.php` file:\n\n```php\n'supported_locales' =\u003e ['en', 'nl'];\n```\n\nBy default, the `UrlDetector` will look for these locales in the URL.\n\nYou can also use one or more custom slugs for a locale:\n\n```php\n'supported_locales' =\u003e [\n    'en' =\u003e 'english-slug',\n    'nl' =\u003e ['dutch-slug', 'nederlandse-slug'],\n];\n```\n\nOr you can use one or more custom domains for a locale:\n\n```php\n'supported_locales' =\u003e [\n    'en' =\u003e 'english-domain.test',\n    'nl' =\u003e ['dutch-domain.test', 'nederlands-domain.test'],\n];\n```\n\n## 🔍 Detectors\n\nBy default, the middleware will use the following detectors to check for a supported locale in:\n\n|  #  | Detector                | Description                                                            |\n|:---:|-------------------------|------------------------------------------------------------------------|\n| 1.  | `RouteActionDetector`   | Checks for a locale in a custom route action.                          |\n| 2.  | `UrlDetector`           | Tries to find a locale based on the URL slugs or domain.               |\n| 3.  | `OmittedLocaleDetector` | Required if an omitted locale is configured. This will always be used. |\n| 4.  | `UserDetector`          | Checks a configurable `locale` attribute on the authenticated user.    |\n| 5.  | `SessionDetector`       | Checks the session for a previously stored locale.                     |\n| 6.  | `CookieDetector`        | Checks a cookie for a previously stored locale.                        |\n| 7.  | `BrowserDetector`       | Checks the preferred language settings of the visitor's browser.       |\n| 8.  | `AppDetector`           | Checks the default app locale as a last resort.                        |\n\nUpdate the `detectors` array in the config file to choose which detectors to run and in what order.\n\n\u003e You can create your own detector by implementing the `CodeZero\\Localizer\\Detectors\\Detector` interface\n\u003e and add a reference to it in the config file. The detectors are resolved from Laravel's IOC container,\n\u003e so you can add any dependencies to your constructor.\n\n## 💾 Stores\n\nThe first supported locale that is returned by a detector will automatically be stored in:\n\n|  #  | Store          | Description                               |\n|:---:|----------------|-------------------------------------------|\n| 1.  | `SessionStore` | Stores the locale in the session.         |\n| 2.  | `CookieStore`  | Stores the locale in a cookie.            |\n| 3.  | `AppStore`     | Sets the locale as the active app locale. |\n\nUpdate the `stores` array in the config file to choose which stores to use.\n\n\u003e You can create your own store by implementing the `CodeZero\\Localizer\\Stores\\Store` interface \n\u003e and add a reference to it in the config file. The stores are resolved from Laravel's IOC container, \n\u003e so you can add any dependencies to your constructor.\n\n## 🛠 More Configuration\n\n### ☑ `omitted_locale`\n\nIf you don't want your main locale to have a slug, you can set it as the `omitted_locale` (not the custom slug).\n\nIf you do this, no additional detectors will run after the `UrlDetector` and `OmittedLocaleDetector`.\nThis makes sense, because the locale will always be determined by those two in this scenario.\n\nExample:\n\n```php\n'omitted_locale' =\u003e 'en',\n```\n\nResult:\n\n- /example-route (English without slug)\n- /nl/example-route (Other locales with slug)\n\nDefault: `null`\n\n### ☑ `trusted_detectors`\n\nAdd any detector class name to this array to make it trusted. (do not remove it from the `detectors` array)\nWhen a trusted detector returns a locale, it will be used as the app locale, regardless if it's a supported locale or not.\n\nDefault: `[]`\n\n### ☑ `url_segment`\n\nThe index of the URL segment that has the locale, when using the `UrlDetector`.\n\nDefault: `1`\n\n### ☑ `route_action`\n\nThe custom route action that holds the locale, when using the `RouteActionDetector`.\n\nDefault: `locale`\n\nTo use the custom route action `locale`, you register a route like this:\n\n```php\nRoute::group(['locale' =\u003e 'nl'], function () {\n    //Route::get(...);\n});\n```\n\n### ☑ `user_attribute`\n\nThe attribute on the user model that holds the locale, when using the `UserDetector`.\nIf the user model does not have this attribute, this detector check will be skipped.\n\nDefault: `locale`\n\n### ☑ `session_key`\n\nThe session key that holds the locale, when using the `SessionDetector` and `SessionStore`.\n\nDefault: `locale`\n\n### ☑ `cookie_name`\n\nThe name of the cookie that holds the locale, when using the `CookieDetector` and `CookieStore`.\n\nDefault: `locale`\n\n### ☑ `cookie_minutes`\n\nThe lifetime of the cookie that holds the locale, when using the `CookieStore`.\n\nDefault: `60 * 24 * 365` (1 year)\n\n## 🚧 Testing\n\n```bash\ncomposer test\n```\n\n## ☕ Credits\n\n- [Ivan Vermeyen](https://github.com/ivanvermeyen)\n- [All contributors](https://github.com/codezero-be/laravel-localizer/contributors)\n\n## 🔒 Security\n\nIf you discover any security related issues, please [e-mail me](mailto:ivan@codezero.be) instead of using the issue tracker.\n\n## 📑 Changelog\n\nA complete list of all notable changes to this package can be found on the\n[releases page](https://github.com/codezero-be/laravel-localizer/releases).\n\n## 📜 License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodezero-be%2Flaravel-localizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodezero-be%2Flaravel-localizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodezero-be%2Flaravel-localizer/lists"}