{"id":13396273,"url":"https://github.com/mcamara/laravel-localization","last_synced_at":"2025-05-13T18:04:55.388Z","repository":{"id":10257757,"uuid":"12367224","full_name":"mcamara/laravel-localization","owner":"mcamara","description":"Easy localization for Laravel","archived":false,"fork":false,"pushed_at":"2025-03-22T15:08:35.000Z","size":813,"stargazers_count":3463,"open_issues_count":48,"forks_count":511,"subscribers_count":90,"default_branch":"master","last_synced_at":"2025-05-06T17:13:48.899Z","etag":null,"topics":["language-selector","laravel","laravel-localization","laravel-package","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"EKMallon/BMA250","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcamara.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["mcamara","iwasherefirst2"]}},"created_at":"2013-08-25T23:14:30.000Z","updated_at":"2025-05-05T11:30:36.000Z","dependencies_parsed_at":"2023-01-13T15:50:04.661Z","dependency_job_id":"d1f0d29d-3533-4924-89cd-f14975f9417f","html_url":"https://github.com/mcamara/laravel-localization","commit_stats":{"total_commits":430,"total_committers":123,"mean_commits":"3.4959349593495936","dds":0.6186046511627907,"last_synced_commit":"42ea38fd3c6f4aeea9273c5a6da9a2d489fd8a41"},"previous_names":[],"tags_count":109,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcamara%2Flaravel-localization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcamara%2Flaravel-localization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcamara%2Flaravel-localization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcamara%2Flaravel-localization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcamara","download_url":"https://codeload.github.com/mcamara/laravel-localization/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254000824,"owners_count":21997441,"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":["language-selector","laravel","laravel-localization","laravel-package","php"],"created_at":"2024-07-30T18:00:43.578Z","updated_at":"2025-05-13T18:04:55.363Z","avatar_url":"https://github.com/mcamara.png","language":"PHP","funding_links":["https://github.com/sponsors/mcamara","https://github.com/sponsors/iwasherefirst2"],"categories":["Popular Packages","PHP","Paquetes utiles","后端开发框架及项目","国际化和本地化(Internationalisation and Localisation)"],"sub_categories":["PHP开发"],"readme":"# Laravel Localization\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/mcamara/laravel-localization.svg?style=flat-square)](https://packagist.org/packages/mcamara/laravel-localization)\n[![Total Downloads](https://img.shields.io/packagist/dt/mcamara/laravel-localization.svg?style=flat-square)](https://packagist.org/packages/mcamara/laravel-localization)\n![GitHub Actions](https://github.com/mcamara/laravel-localization/actions/workflows/run-tests.yml/badge.svg)\n[![Open Source Helpers](https://www.codetriage.com/mcamara/laravel-localization/badges/users.svg)](https://www.codetriage.com/mcamara/laravel-localization)\n[![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)\n\nEasy i18n localization for Laravel, an useful tool to combine with Laravel localization classes.\n\nThe package offers the following:\n\n - Detect language from browser\n - Smart redirects (Save locale in session/cookie)\n - Smart routing (Define your routes only once, no matter how many languages you use)\n - Translatable Routes\n - Supports caching \u0026 testing\n - Option to hide default locale in url\n - Many snippets and helpers (like language selector)\n\n## Table of Contents\n\n- \u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e\n- \u003ca href=\"#usage\"\u003eUsage\u003c/a\u003e\n- \u003ca href=\"#redirect-middleware\"\u003eRedirect Middleware\u003c/a\u003e\n- \u003ca href=\"#helpers\"\u003eHelpers\u003c/a\u003e\n- \u003ca href=\"#translated-routes\"\u003eTranslated Routes\u003c/a\u003e\n- \u003ca href=\"#caching-routes\"\u003eCaching routes\u003c/a\u003e\n- \u003ca href=\"#testing\"\u003eTesting\u003c/a\u003e\n- \u003ca href=\"#common-issues\"\u003eCommon Issues\u003c/a\u003e\n    - \u003ca href=\"#post-is-not-working\"\u003ePOST is not working\u003c/a\u003e\n    - \u003ca href=\"#methodnotallowedhttpexception\"\u003eMethodNotAllowedHttpException\u003c/a\u003e\n    - \u003ca href=\"#validation-message-is-only-in-default-locale\"\u003eValidation message is always in default locale\u003c/a\u003e\n- \u003ca href=\"#collaborators\"\u003eCollaborators\u003c/a\u003e\n- \u003ca href=\"#changelog\"\u003eChangelog\u003c/a\u003e\n- \u003ca href=\"#license\"\u003eLicense\u003c/a\u003e\n\n## Laravel compatibility\n\n Laravel      | laravel-localization\n:-------------|:----------\n 4.0.x        | 0.13.x\n 4.1.x        | 0.13.x\n 4.2.x        | 0.15.x\n 5.0.x/5.1.x  | 1.0.x\n 5.2.x-5.4.x (PHP 7 not required)  | 1.2.\n 5.2.0-6.x (PHP version \u003e= 7 required) | 1.4.x\n 6.x-10.x (PHP version \u003e= 7 required) | 1.8.x\n 10.x-12.x (PHP version \u003e= 8.2 required) | 2.0.x\n\n## Installation\n\nInstall the package via composer: `composer require mcamara/laravel-localization`\n\nFor Laravel 5.4 and below it necessary to [register the service provider](/ADDITIONS.md#for-laravel-5.4-and-below).\n\n### Config Files\n\nIn order to edit the default configuration you may execute:\n\n```\nphp artisan vendor:publish --provider=\"Mcamara\\LaravelLocalization\\LaravelLocalizationServiceProvider\"\n```\n\nAfter that, `config/laravellocalization.php` will be created.\n\nThe configuration options are:\n\n - **supportedLocales** Languages of your app (Default: English \u0026 Spanish).\n - **useAcceptLanguageHeader** If true, then automatically detect language from browser.\n - **hideDefaultLocaleInURL** If true, then do not show default locale in url.\n - **localesOrder** Sort languages in custom order.\n - **localesMapping** Rename url locales.\n - **utf8suffix** Allow changing utf8suffix for CentOS etc.\n - **urlsIgnored** Ignore specific urls.\n\n### Register Middleware\n\nYou may register the package middleware in the `app/Http/Kernel.php` file:\n\n```php\n\u003c?php namespace App\\Http;\n\nuse Illuminate\\Foundation\\Http\\Kernel as HttpKernel;\n\nclass Kernel extends HttpKernel {\n    /**\n    * The application's route middleware.\n    *\n    * @var array\n    */\n    protected $middlewareAliases = [\n        /**** OTHER MIDDLEWARE ****/\n        'localize'                =\u003e \\Mcamara\\LaravelLocalization\\Middleware\\LaravelLocalizationRoutes::class,\n        'localizationRedirect'    =\u003e \\Mcamara\\LaravelLocalization\\Middleware\\LaravelLocalizationRedirectFilter::class,\n        'localeSessionRedirect'   =\u003e \\Mcamara\\LaravelLocalization\\Middleware\\LocaleSessionRedirect::class,\n        'localeCookieRedirect'    =\u003e \\Mcamara\\LaravelLocalization\\Middleware\\LocaleCookieRedirect::class,\n        'localeViewPath'          =\u003e \\Mcamara\\LaravelLocalization\\Middleware\\LaravelLocalizationViewPath::class\n    ];\n}\n```\n\nIf you are using Laravel 11, you may register in `bootstrap/app.php` file in closure `withMiddleware`:\n\n```php\nreturn Application::configure(basePath: dirname(__DIR__))\n    // Other application configurations\n    -\u003ewithMiddleware(function (Middleware $middleware) {\n        $middleware-\u003ealias([\n            /**** OTHER MIDDLEWARE ALIASES ****/\n            'localize'                =\u003e \\Mcamara\\LaravelLocalization\\Middleware\\LaravelLocalizationRoutes::class,\n            'localizationRedirect'    =\u003e \\Mcamara\\LaravelLocalization\\Middleware\\LaravelLocalizationRedirectFilter::class,\n            'localeSessionRedirect'   =\u003e \\Mcamara\\LaravelLocalization\\Middleware\\LocaleSessionRedirect::class,\n            'localeCookieRedirect'    =\u003e \\Mcamara\\LaravelLocalization\\Middleware\\LocaleCookieRedirect::class,\n            'localeViewPath'          =\u003e \\Mcamara\\LaravelLocalization\\Middleware\\LaravelLocalizationViewPath::class,\n        ]);\n    })\n```\n\n## Usage\n\nAdd the following to your routes file:\n\n```php\n// routes/web.php\n\nRoute::group(['prefix' =\u003e LaravelLocalization::setLocale()], function()\n{\n\t/** ADD ALL LOCALIZED ROUTES INSIDE THIS GROUP **/\n\tRoute::get('/', function()\n\t{\n\t\treturn View::make('hello');\n\t});\n\n\tRoute::get('test',function(){\n\t\treturn View::make('test');\n\t});\n});\n\n/** OTHER PAGES THAT SHOULD NOT BE LOCALIZED **/\n\n```\n\nOnce this route group is added to the routes file, a user can access all locales added into `supportedLocales` (`en` and `es` by default).\nFor example, the above route file creates the following addresses:\n\n```\n// Set application language to English\nhttp://url-to-laravel/en\nhttp://url-to-laravel/en/test\n\n// Set application language to Spanish\nhttp://url-to-laravel/es\nhttp://url-to-laravel/es/test\n\n// Set application language to English or Spanish (depending on browsers default locales)\n// if nothing found set to default locale\nhttp://url-to-laravel\nhttp://url-to-laravel/test\n```\nThe package sets your application locale `App::getLocale()` according to your url. The locale may then be used for [Laravel's localization features](http://laravel.com/docs/localization).\n\nYou may add middleware to your group like this:\n\n```php\nRoute::group(\n[\n\t'prefix' =\u003e LaravelLocalization::setLocale(),\n\t'middleware' =\u003e [ 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath' ]\n], function(){ //...\n});\n```\n\n### Recommendations\n\n***1.***: It is **strongly** recommended to use a [redirecting middleware](#redirect-middleware).\nUrls without locale should only be used to determine browser/default locale and to redirect to the [localized url](#localized-urls).\nOtherwise, when search engine robots crawl for example `http://url-to-laravel/test` they may get different language content for each visit.\nAlso having multiple urls for the same content creates a SEO duplicate-content issue.\n\n***2.***: It is **strongly** recommended to [localize your links](#localized-urls), even if you use a redirect middleware.\nOtherwise, you will cause at least one redirect each time a user clicks on a link.\nAlso, any action url from a post form must be localized, to prevent that it gets redirected to a get request.\n\n\n## Redirect Middleware\n\nThe following redirection middleware depends on the settings of `hideDefaultLocaleInURL`\nand `useAcceptLanguageHeader` in `config/laravellocalization.php`:\n\n### LocaleSessionRedirect\n\nWhenever a locale is present in the url, it will be stored in the session by this middleware.\n\nIf there is no locale present in the url, then this middleware will check the following\n\n - If no locale is saved in session and `useAcceptLanguageHeader` is set to true, compute locale from browser and redirect to url with locale.\n - If a locale is saved in session redirect to url with locale, unless its the default locale and `hideDefaultLocaleInURL` is set to true.\n\nFor example, if a user navigates to http://url-to-laravel/test  and `en` is the current locale, it would redirect him automatically to http://url-to-laravel/en/test.\n\n### LocaleCookieRedirect\n\nSimilar to LocaleSessionRedirect, but it stores value in a cookie instead of a session.\n\nWhenever a locale is present in the url, it will be stored in the cookie by this middleware.\n\nIn there is no locale present in the url, then this middleware will check the following\n\n - If no locale is saved in cookie and `useAcceptLanguageHeader` is set to true, compute locale from browser and redirect to url with locale.\n - If a locale is saved in cookie redirect to url with locale, unless its the default locale and `hideDefaultLocaleInURL` is set to true.\n\nFor example, if a user navigates to http://url-to-laravel/test  and `de` is the current locale, it would redirect him automatically to http://url-to-laravel/de/test.\n\n\n### LaravelLocalizationRedirectFilter\n\nWhen the default locale is present in the url and `hideDefaultLocaleInURL` is set to true, then the middleware redirects to the url without locale.\n\nFor example, if `es` is the default locale, then http://url-to-laravel/es/test would be redirected to http://url-to-laravel/test and the`App::getLocale()` would be\nset to `es`.\n\n\n## Helpers\n\nThis package comes with a bunch of helpers.\n\n### Localized URLs\nLocalized URLS  taken into account [route model binding]([https://laravel.com/docs/master/routing#route-model-binding]) when generating the localized route,\naswell as the `hideDefaultLocaleInURL` and [Translated Routes](#translated-routes) settings.\n\n\n#### Get localized URL\n\n```php\n    // If current locale is Spanish, it returns `/es/test`\n    \u003ca href=\"{{ LaravelLocalization::localizeUrl('/test') }}\"\u003e@lang('Follow this link')\u003c/a\u003e\n```\n\n#### Get localized URL for an specific locale\nGet current URL in specific locale:\n\n```php\n// Returns current url with English locale.\n{{ LaravelLocalization::getLocalizedURL('en') }}\n```\n\n### Get Clean routes\n\nReturns a URL clean of any localization.\n\n```php\n// Returns /about\n{{ LaravelLocalization::getNonLocalizedURL('/es/about') }}\n```\n\n### Get URL for an specific translation key\n\nReturns a route, [localized](#translated-routes) to the desired locale. If the translation key does not exist in the locale given, this function will return false.\n\n\n```php\n// Returns /es/acerca\n{{ LaravelLocalization::getURLFromRouteNameTranslated('es', 'routes.about') }}\n```\n**Example of a localized link using routes with attributes**\n\n```php\n// An array of attributes can be provided.\n// Returns /en/archive/ghosts, /fr/archive/fantômes, /pt/arquivo/fantasmas, etc.\n\u003ca href=\"{{ LaravelLocalization::getURLFromRouteNameTranslated( App::currentLocale(), 'routes.archive', array('category' =\u003e 'ghosts')) }}\"\u003eGhost Stories\u003c/a\u003e\n```\n\n\n### Get Supported Locales\n\nReturn all supported locales and their properties as an array.\n\n```php\n{{ LaravelLocalization::getSupportedLocales() }}\n```\n\n\n\n### Get Supported Locales Custom Order\n\nReturn all supported locales but in the order specified in the configuration file. You can use this function to print locales in the language selector.\n\n```php\n{{ LaravelLocalization::getLocalesOrder() }}\n```\n\n### Get Supported Locales Keys\n\nReturn an array with all the keys for the supported locales.\n\n```php\n{{ LaravelLocalization::getSupportedLanguagesKeys() }}\n```\n\n### Get Current Locale\n\nReturn the key of the current locale.\n\n```php\n{{ LaravelLocalization::getCurrentLocale() }}\n```\n\n### Get Current Locale Name\nReturn current locale's name as string (English/Spanish/Arabic/ ..etc).\n\n```php\n{{ LaravelLocalization::getCurrentLocaleName() }}\n```\n\n### Get Current Locale Native Name\nReturn current locale's native name as string (English/Español/عربى/ ..etc).\n\n```php\n{{ LaravelLocalization::getCurrentLocaleNative() }}\n```\n\n### Get Current Locale Regional Name\nReturn current locale's regional name as string (en_GB/en_US/fr_FR/ ..etc).\n\n```php\n{{ LaravelLocalization::getCurrentLocaleRegional() }}\n```\n\n### Get Current Locale Direction\n\nReturn current locale's direction as string (ltr/rtl).\n\n\n```php\n{{ LaravelLocalization::getCurrentLocaleDirection() }}\n```\n\n\n\n### Get Current Locale Script\nReturn the [ISO 15924](http://www.unicode.org/iso15924) code for the current locale script as a string; \"Latn\", \"Cyrl\", \"Arab\", etc.\n\n```php\n{{ LaravelLocalization::getCurrentLocaleScript() }}\n```\n\n### Set view-base-path to current locale\n\nRegister the middleware `LaravelLocalizationViewPath` to set current locale as view-base-path.\n\nNow you can wrap your views in language-based folders like the translation files.\n\n`resources/views/en/`, `resources/views/fr`, ...\n\n\n### Map your own custom lang url segments\n\nAs you can modify the supportedLocales even by renaming their keys, it is possible to use the string ```uk``` instead of ```en-GB``` to provide custom lang url segments. Of course, you need to prevent any collisions with already existing keys and should stick to the convention as long as possible. But if you are using such a custom key, you have to store your mapping to the ```localesMapping``` array. This ```\nlocalesMapping``` is needed to enable the LanguageNegotiator to correctly assign the desired locales based on HTTP Accept Language Header. Here is a quick example how to map HTTP Accept Language Header 'en-GB' to url segment 'uk':\n\n```php\n// config/laravellocalization.php\n\n'localesMapping' =\u003e [\n\t'en-GB' =\u003e 'uk'\n],\n```\n\nAfter that ```http://url-to-laravel/en-GB/a/b/c``` becomes ```http://url-to-laravel/uk/a/b/c```.\n\n```php\nLaravelLocalization::getLocalizedURL('en-GB', 'a/b/c'); // http://url-to-laravel/uk/a/b/c\nLaravelLocalization::getLocalizedURL('uk', 'a/b/c'); // http://url-to-laravel/uk/a/b/c\n```\n\n## Creating a language selector\n\nIf you're supporting multiple locales in your project you will probably want to provide the users with a way to change language. Below is a simple example of blade template code you can use to create your own language selector.\n\n```blade\n\u003cul\u003e\n    @foreach(LaravelLocalization::getSupportedLocales() as $localeCode =\u003e $properties)\n        \u003cli\u003e\n            \u003ca rel=\"alternate\" hreflang=\"{{ $localeCode }}\" href=\"{{ LaravelLocalization::getLocalizedURL($localeCode, null, [], true) }}\"\u003e\n                {{ $properties['native'] }}\n            \u003c/a\u003e\n        \u003c/li\u003e\n    @endforeach\n\u003c/ul\u003e\n```\nHere default language will be forced in getLocalizedURL() to be present in the URL even `hideDefaultLocaleInURL = true`.\n\nNote that Route Model Binding is supported.\n\n## Translated Routes\n\nYou may translate your routes. For example, http://url/en/about and http://url/es/acerca (acerca is about in spanish)\nor http://url/en/article/important-article and http://url/es/articulo/important-article (article is articulo in spanish) would be redirected to the same controller/view as follows:\n\nIt is necessary that at least the `localize` middleware in loaded in your `Route::group` middleware (See [installation instruction](#installation)).\n\nFor each language, add a `routes.php` into `resources/lang/**/routes.php` folder.\nThe file contains an array with all translatable routes. For example, like this:\n\n\u003e Keep in mind: starting from [Laravel 9](https://laravel.com/docs/9.x/upgrade#the-lang-directory), the `resources/lang` folder is now located in the root project folder (`lang`).\n\u003e If your project has `lang` folder in the root, you must add a `routes.php` into `lang/**/routes.php` folder.\n\n```php\n\u003c?php\n// resources/lang/en/routes.php\nreturn [\n    \"about\"    =\u003e  \"about\",\n    \"article\"  =\u003e  \"article/{article}\",\n];\n```\n```php\n\u003c?php\n// resources/lang/es/routes.php\nreturn [\n    \"about\"    =\u003e  \"acerca\",\n    \"article\"  =\u003e  \"articulo/{article}\",\n];\n```\n\nYou may add the routes in `routes/web.php` like this:\n\n```php\nRoute::group(['prefix' =\u003e LaravelLocalization::setLocale(),\n              'middleware' =\u003e [ 'localize' ]], function () {\n\n    Route::get(LaravelLocalization::transRoute('routes.about'), function () {\n        return view('about');\n    });\n\n    Route::get(LaravelLocalization::transRoute('routes.article'), function (\\App\\Article $article) {\n        return $article;\n    });\n\n    //,...\n});\n```\n\nOnce files are saved, you can access http://url/en/about , http://url/es/acerca , http://url/en/article/important-article and http://url/es/articulo/important-article without any problem.\n\n### Translatable route parameters\n\nMaybe you noticed in the previous example the English slug in the Spanish url:\n\n    http://url/es/articulo/important-article\n\nIt is possible to have translated slugs, for example like this:\n\n    http://url/en/article/important-change\n    http://url/es/articulo/cambio-importante\n\nHowever, in order to do this, each article must have many slugs (one for each locale).\nIts up to you how you want to implement this relation. The only requirement for translatable route parameters is, that the relevant model implements the interface `LocalizedUrlRoutable`.\n\n#### Implementing LocalizedUrlRoutable\n\nTo implement `\\Mcamara\\LaravelLocalization\\Interfaces\\LocalizedUrlRoutable`,\none has to create the function `getLocalizedRouteKey($locale)`, which must return for a given locale the translated slug. In the above example, inside the model article, `getLocalizedRouteKey('en')` should return `important-change` and `getLocalizedRouteKey('es')` should return `cambio-importante`.\n\n#### Route Model Binding\n\nTo use [route-model-binding](https://laravel.com/docs/routing#route-model-binding), one  should overwrite the function `resolveRouteBinding($slug)`\nin the model. The function should return the model that belongs to the translated slug `$slug`.\nFor example:\n\n```php\npublic function resolveRouteBinding($slug)\n{\n        return static::findByLocalizedSlug($slug)-\u003efirst() ?? abort(404);\n}\n```\n\n#### Tutorial Video\n\nYou may want to checkout this [video](https://youtu.be/B1AUqCdizgc) which demonstrates how one may set up translatable route parameters.\n\n## Events\n\nYou can capture the URL parameters during translation if you wish to translate them too. To do so, just create an event listener for the `routes.translation` event like so:\n\n```php\nEvent::listen('routes.translation', function($locale, $attributes)\n{\n\t// Do your magic\n\n\treturn $attributes;\n});\n```\n\nBe sure to pass the locale and the attributes as parameters to the closure. You may also use Event Subscribers, see: [http://laravel.com/docs/events#event-subscribers](http://laravel.com/docs/events#event-subscribers)\n\n## Caching routes\n\nTo cache your routes, use:\n\n``` bash\nphp artisan route:trans:cache\n```\n\n... instead of the normal `route:cache` command. Using `artisan route:cache` will **not** work correctly!\n\nFor the route caching solution to work, it is required to make a minor adjustment to your application route provision.\n\n**before laravel 11** \n\nIn your App's `RouteServiceProvider`, use the `LoadsTranslatedCachedRoutes` trait:\n\n```php\n\u003c?php\nclass RouteServiceProvider extends ServiceProvider\n{\n    use \\Mcamara\\LaravelLocalization\\Traits\\LoadsTranslatedCachedRoutes;\n```\n\n**after laravel 11** \n\nIn your App's `AppServiceProvider`, use the `CachedTranslatedRouteLoader` class in register method:\n\n```php\n\u003c?php\nclass AppServiceProvider extends ServiceProvider\n{  \n    use \\Mcamara\\LaravelLocalization\\Traits\\LoadsTranslatedCachedRoutes;\n    /**\n     * Bootstrap any application services.\n     */\n    public function boot(): void\n    {\n        RouteServiceProvider::loadCachedRoutesUsing(fn() =\u003e $this-\u003eloadCachedRoutes());\n        ...\n    }   \n```\n\n\n\nFor more details see [here](CACHING.md).\n\n## Common Issues\n\n### POST is not working\n\nThis may happen if you do not localize your action route that is inside your `Routes::group`.\nThis may cause a redirect, which then changes the post request into a get request.\nTo prevent that, simply use the [localize helper](#get-localized-url).\n\nFor example, if you use `Auth::routes()` and put them into your `Route::group` Then\n\n```\n\u003cform action=\"/logout\" method=\"POST\"\u003e\n\u003cbutton\u003eLogout\u003c/button\u003e\n\u003c/form\u003e\n```\n\nwill not work. Instead, one has to use\n\n```php\n\u003cform action=\"{{  \\LaravelLocalization::localizeURL('/logout') }} \" method=\"POST\"\u003e\n\u003cbutton\u003eLogout\u003c/button\u003e\n\u003c/form\u003e\n```\n\n\nAnother way to solve this is to put http method to config to 'laravellocalization.httpMethodsIgnored'\nto prevent of processing this type of requests\n\n### MethodNotAllowedHttpException\n\nIf you do not localize your post url and use a redirect middleware,\nthen the post request gets redirected as a get request.\nIf you have not defined such a get route, you will cause this exception.\n\nTo localize your post url see the example in [POST is not working](#post-is-not-working).\n\n### Validation message is only in default locale\n\nThis also happens if you did not localize your post url.\nIf you don't localize your post url, the default locale is set while validating,\nand when returning to `back()` it shows the validation message in default locale.\n\nTo localize your post url see the example in [POST is not working](#post-is-not-working).\n\n## Testing\n\nDuring the test setup, the called route is not yet known. This means no language can be set.\nWhen a request is made during a test, this results in a 404 - without the prefix set the localized route does not seem to exist.\n\nTo fix this, you can use this function to manually set the language prefix:\n```php\n// TestCase.php\nprotected function refreshApplicationWithLocale($locale)\n{\n    self::tearDown();\n    putenv(LaravelLocalization::ENV_ROUTE_KEY . '=' . $locale);\n    self::setUp();\n}\n\nprotected function tearDown(): void\n{\n    putenv(LaravelLocalization::ENV_ROUTE_KEY);\n    parent::tearDown();\n}\n\n// YourTest.php\npublic function testBasicTest()\n{\n    $this-\u003erefreshApplicationWithLocale('en');\n    // Testing code\n}\n```\n\n## Collaborators\n- [Adam Nielsen (iwasherefirst2)](https://github.com/iwasherefirst2)\n\nAsk [mcamara](https://github.com/mcamara) if you want to be one of them!\n\n## Changelog\n\nView changelog here -\u003e [changelog](CHANGELOG.md)\n\n## License\n\nLaravel Localization is an open-sourced laravel package licensed under the MIT license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcamara%2Flaravel-localization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcamara%2Flaravel-localization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcamara%2Flaravel-localization/lists"}