{"id":15561156,"url":"https://github.com/alkhatibdev/language-switcher","last_synced_at":"2025-04-23T21:49:44.570Z","repository":{"id":57749657,"uuid":"524733279","full_name":"alkhatibdev/language-switcher","owner":"alkhatibdev","description":"Laravel dynamic language switcher for both web and API routes with various supported options.","archived":false,"fork":false,"pushed_at":"2024-03-07T18:46:26.000Z","size":384,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-23T21:49:37.128Z","etag":null,"topics":["languages","laravel","laravel-framework","localization","php"],"latest_commit_sha":null,"homepage":"https://alkhatibdev.github.io/language-switcher/","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/alkhatibdev.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-14T17:13:20.000Z","updated_at":"2025-04-23T12:17:50.000Z","dependencies_parsed_at":"2024-03-07T19:44:45.978Z","dependency_job_id":"42b1aee0-24a1-470c-b11f-e098cc65d4b1","html_url":"https://github.com/alkhatibdev/language-switcher","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"ed630b991b059ea07ac90a728150909cf3e66f28"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alkhatibdev%2Flanguage-switcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alkhatibdev%2Flanguage-switcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alkhatibdev%2Flanguage-switcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alkhatibdev%2Flanguage-switcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alkhatibdev","download_url":"https://codeload.github.com/alkhatibdev/language-switcher/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250522294,"owners_count":21444510,"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":["languages","laravel","laravel-framework","localization","php"],"created_at":"2024-10-02T16:05:47.094Z","updated_at":"2025-04-23T21:49:44.541Z","avatar_url":"https://github.com/alkhatibdev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/alkhatibdev/language-switcher/main/socialcard.png\" alt=\"Social Card of Language Switcher Package\"\u003e\u003c/p\u003e\n\n# Laravel dynamic language switcher\n\n[![Latest Version](https://img.shields.io/github/release/alkhatibdev/language-switcher.svg?style=flat-square)](https://github.com/alkhatibdev/language-switcher/releases)\n![Packagist Downloads (custom server)](https://img.shields.io/packagist/dt/alkhatibdev/language-switcher)\n[![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n\n# Introduction\nLaravel dynamic language switcher for both web and API routes with various supported options.\n\n## Features\n\n- Switch user locale automatically and remind newly selected language for all next requests.\n- Support language switching via `request body/query keys`, `request headers keys`, and `route parameters names`.\n- Support API routes (Switch language via headers for stateless requests).\n- Support all HTTP methods (GET, POST, PUT and ..etc).\n- SEO-friendly routes by supporting language switching depending on route parameters.\n- Everything is configurable with a rich and well-documented [configuration file](https://github.com/alkhatibdev/language-switcher/blob/main/config/language-switcher.php).\n\n# Installation\n\n## install via composer\n\n```bash\ncomposer require alkhatibdev/language-switcher\n```\n\n## Publish Configs \n```bash\nphp artisan vendor:publish --tag=language-switcher-config\n```\nA `language-switcher.php` config file will be published on your `configs` directory. Feel free to read and override all these configurable parts, or stick with the [defaults configs](https://github.com/alkhatibdev/language-switcher/blob/main/config/language-switcher.php)\n\n\u003cbr\u003e\n\n# Usage\n\n## Basic Usage\nEverything is set out of the box, start calling your routes with these supported options:\n\n### Via Request query/body keys\n```bash\n// Request query key/value\nhttp://example.com/?lang=en\n\n// Request magic keys\nhttp://example.com/?en\n\n// Also you can use the same above parameters with the body of POST or PUT\ncurl -X POST http://example.com/api/users\n     -d '{\"lang\": \"en\"}'  \n```\n\n\n### Via request headers keys\n```bash\ncurl --header \"Accept-Language: en\" http://example.com/api/users\n```\n\n### Via route parameters \nFor given route: `Route::get('/{locale}/home', [HomeController, 'home']);`\n\n```\nhttp://example.com/en/home\n```\n\n\u003cbr\u003e\n\n\u003e **Note**\n\u003e \u003cbr\u003e- All previous examples will ask the package to switch locale to `'en'`.\n\u003e \u003cbr\u003e- Upcoming requests still remind this newly set locale.\n\n\u003cbr\u003e\n\n## Customize Package Scope\n\nBy default, the package middleware is assigned globally to all your routes. However, you can disable `assign_globally` from the package config file, and assign middleware `alias` to all routes and route groups manually.\n\n### Disable global assignment\n```php\n// config/language-switcher.php\n\n'assign_globally' =\u003e false,\n```\n\n### Assign to route or route groups\n```php\n// routes/web.php\n\n// Assign to individual route\nRoute::get('/{locale}/home', [HomeController, 'home'])-\u003emiddleware(['switchlocale']);\n\n\n// Assign to route group\nRoute::-\u003emiddleware(['switchlocale'])-\u003egroup(function () {\n    //\n});\n```\n\n### Assign to middleware groups\n```php\n// app/Http/kernel.php\n\nprotected $middlewareGroups = [\n    'web' =\u003e [\n        // ...\n        'switchlocale',\n    ],\n\n    'api' =\u003e [\n        // ...\n        'switchlocale',\n    ],\n];\n```\n\n### Disable Saving\n\nBy default, the package uses sessions to store the current locale, switched by a user, to keep the newly selected locale active for the next requests without a need to pass the locale in every request. However, if you want to stop this behavior, set `enable_session` to `false`.\n\n\n```php\n// config/language-switcher.php\n\n'enable_session' =\u003e false,\n```\n\n\u003cbr\u003e\n\n# License\n\nLanguage Switcher is open-sourced software licensed under the [MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falkhatibdev%2Flanguage-switcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falkhatibdev%2Flanguage-switcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falkhatibdev%2Flanguage-switcher/lists"}