{"id":15480194,"url":"https://github.com/tyler36/localization","last_synced_at":"2026-05-19T19:06:50.897Z","repository":{"id":57074151,"uuid":"136414749","full_name":"tyler36/localization","owner":"tyler36","description":"Localization middlewares","archived":false,"fork":false,"pushed_at":"2021-09-21T06:04:57.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-19T04:30:47.718Z","etag":null,"topics":["i18n","laravel","laravel-package","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/tyler36.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-07T03:05:33.000Z","updated_at":"2022-10-20T03:18:05.000Z","dependencies_parsed_at":"2022-08-24T14:54:49.577Z","dependency_job_id":null,"html_url":"https://github.com/tyler36/localization","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/tyler36/localization","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyler36%2Flocalization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyler36%2Flocalization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyler36%2Flocalization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyler36%2Flocalization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tyler36","download_url":"https://codeload.github.com/tyler36/localization/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyler36%2Flocalization/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266535695,"owners_count":23944275,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["i18n","laravel","laravel-package","localization","middleware"],"created_at":"2024-10-02T04:41:07.111Z","updated_at":"2026-05-19T19:06:45.876Z","avatar_url":"https://github.com/tyler36.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction\nThis package is designed to simplify multi-locale applications.\nSimply add the required middleware and update your configuration.\n\n## Installation\n- Install package\n```\ncomposer require tyler36/localization\n```\n\n- Publish configuration\nRun the command below to publish the configuration file\n```\nphp artisan vendor:publish --provider=tyler36/localization\n```\n\n- Add supported languages\nBy default, only the current app locale is deemed valid.\nYou can add additional languages to configuration file (```config/localization.php```). 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.\n\n- Apply middleware\nAdd the desired middle to the ```app/Http/Kernel.php``` file in the required location. For more details, see the Laravel documentation (https://laravel.com/docs/master/middleware#registering-middleware)\n\n\n## Middleware\n\n### Option 1: Header request\nThis middleware uses a request header to set the locale. By default, the query string is set to ```X-localization``` but can be changed through the config file. It's ideal for making request via javascript.\n\n- Register\n```\\Tyler36\\Localization\\Middleware\\HeaderLocale::class```\n\n\n- Set the header in via vanilla javascript or preferred javascript framework. For example, you can apply the header to all ```Axios``` request with the following:\n```\n// Set language to German ('de')\nwindow.axios = axios;\nwindow.axios.defaults.headers.common['X-localization'] = 'de';\n```\nNow, when you send a request to the endpoint Laravel will update the locale to match the setting, assuming it is configured as 'valid'.\n\n\n### Option 2: Query String\nThis middleware is designed to use a query string.\n\n- Register\n```\\Tyler36\\Localization\\Middleware\\QueryStringLocale::class```\n\n- Add the query string to a URL.\nBy default, the query string is set to ```lang``` but can be changed through the config file.\n```\n    // This will return the site with default locale\n    https://cool-site.dev\n\n    // This will return the site with locale to to German (de)\n    https://cool-site.dev?lang=de\n```\n\n\n### Option 3: Member preference\nThis 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.\n\n- Register\n```\\Tyler36\\Localization\\Middleware\\MemberLocale::class```\n\n- Create the attribute on User models\nBy default, the query string is set to ```locale``` but can be changed through the config file.\n```\n    $table-\u003estring('locale', 2)-\u003edefault(app()-\u003egetLocale());\n```\n\n\n### Option 4: Session\nThis middleware looks for a value in Laravel session.\n\n- Register\n```\\Tyler36\\Localization\\Middleware\\SessionLocale::class```\n\n- Create a route that saves the ```session_key =\u003e locale```  to the session\nBy default, the ```session_key``` is set to ```locale``` but can be changed through the config file.\n```\n    $key = config('localization.session_key', 'locale');\n    session([$key =\u003e request()-\u003eget($key)]);\n```\nor you could use the included controller by updating your route file\n```\n// routes/web.php\nRoute::get('/locale/{locale}', [\n    'as' =\u003e 'localization.session',\n    'uses' =\u003e '\\Tyler36\\Localization\\Controller\\LocaleController@session'\n]);\n\n// blade - create links\nroute('localization.session', [config('localization.session_key') =\u003e $locale]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyler36%2Flocalization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftyler36%2Flocalization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyler36%2Flocalization/lists"}