{"action":"created","issue":{"url":"https://api.github.com/repos/nikic/FastRoute/issues/169","repository_url":"https://api.github.com/repos/nikic/FastRoute","labels_url":"https://api.github.com/repos/nikic/FastRoute/issues/169/labels{/name}","comments_url":"https://api.github.com/repos/nikic/FastRoute/issues/169/comments","events_url":"https://api.github.com/repos/nikic/FastRoute/issues/169/events","html_url":"https://github.com/nikic/FastRoute/issues/169","id":333048685,"node_id":"MDU6SXNzdWUzMzMwNDg2ODU=","number":169,"title":"remove defualt language from url","user":{"login":"perspolise","id":19752074,"node_id":"MDQ6VXNlcjE5NzUyMDc0","avatar_url":"https://avatars1.githubusercontent.com/u/19752074?v=4","gravatar_id":"","url":"https://api.github.com/users/perspolise","html_url":"https://github.com/perspolise","followers_url":"https://api.github.com/users/perspolise/followers","following_url":"https://api.github.com/users/perspolise/following{/other_user}","gists_url":"https://api.github.com/users/perspolise/gists{/gist_id}","starred_url":"https://api.github.com/users/perspolise/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/perspolise/subscriptions","organizations_url":"https://api.github.com/users/perspolise/orgs","repos_url":"https://api.github.com/users/perspolise/repos","events_url":"https://api.github.com/users/perspolise/events{/privacy}","received_events_url":"https://api.github.com/users/perspolise/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-06-17T09:19:42Z","updated_at":"2018-06-18T13:21:24Z","closed_at":null,"author_association":"NONE","body":"\r\nI have Multi language CMS For Front and Admin Page.\r\n\r\nFor English language(defualt without `en`):\r\n\r\n`example.com/articles/`\r\n\r\nFor France Language(with `fr`):\r\n\r\n`example.com/fr/articles/`\r\n\r\nNow,  for my url Like This code:\r\n\r\n```\r\n$dispatcher = FastRoute\\simpleDispatcher(function(FastRoute\\RouteCollector $r) {\r\n    $r->addRoute('GET', '/{lang:(?:en|fr)}/articles', 'get_all_users_handler');\r\n});\r\n\r\n\r\n$httpMethod = $_SERVER['REQUEST_METHOD'];\r\n$uri = $_SERVER['REQUEST_URI'];\r\n\r\n// Strip query string (?foo=bar) and decode URI\r\nif (false !== $pos = strpos($uri, '?')) {\r\n    $uri = substr($uri, 0, $pos);\r\n}\r\n$uri = rawurldecode($uri);\r\n\r\n$routeInfo = $dispatcher->dispatch($httpMethod, $uri);\r\nswitch ($routeInfo[0]) {\r\n    case FastRoute\\Dispatcher::NOT_FOUND:\r\n       echo 'BAd';\r\n        break;\r\n    case FastRoute\\Dispatcher::METHOD_NOT_ALLOWED:\r\n        $allowedMethods = $routeInfo[1];\r\n        // ... 405 Method Not Allowed\r\n        break;\r\n    case FastRoute\\Dispatcher::FOUND:\r\n        $handler = $routeInfo[1];\r\n        $vars = $routeInfo[2];\r\n        echo 'Found Found';\r\n        break;\r\n}\r\n\r\n```\r\nMy Url Routed And Work With (`fr` and `en`) path method:\r\n\r\n`example.com/en/articles` and `example.com/fr/articles`.\r\n\r\nBut I need to remove default language from url. How do fix this problem ?!\r\n"},"comment":{"url":"https://api.github.com/repos/nikic/FastRoute/issues/comments/398051686","html_url":"https://github.com/nikic/FastRoute/issues/169#issuecomment-398051686","issue_url":"https://api.github.com/repos/nikic/FastRoute/issues/169","id":398051686,"node_id":"MDEyOklzc3VlQ29tbWVudDM5ODA1MTY4Ng==","user":{"login":"aromot","id":1989670,"node_id":"MDQ6VXNlcjE5ODk2NzA=","avatar_url":"https://avatars0.githubusercontent.com/u/1989670?v=4","gravatar_id":"","url":"https://api.github.com/users/aromot","html_url":"https://github.com/aromot","followers_url":"https://api.github.com/users/aromot/followers","following_url":"https://api.github.com/users/aromot/following{/other_user}","gists_url":"https://api.github.com/users/aromot/gists{/gist_id}","starred_url":"https://api.github.com/users/aromot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aromot/subscriptions","organizations_url":"https://api.github.com/users/aromot/orgs","repos_url":"https://api.github.com/users/aromot/repos","events_url":"https://api.github.com/users/aromot/events{/privacy}","received_events_url":"https://api.github.com/users/aromot/received_events","type":"User","site_admin":false},"created_at":"2018-06-18T13:21:24Z","updated_at":"2018-06-18T13:21:24Z","author_association":"NONE","body":"@perspolise : no I didn't test the code I sent. It wasn't meant to be taken \"as-is\". The idea was more to give a track/hint. I think it's difficult to provide a code you can simply copy/paste and push the button to get it run (a dream we all share to save time and go running in fields of flowers). My main point is to invite you thinking of a strategy to manage the languages for your application. My basic suggestion is:\r\n\r\n1. define a list of available languages for your application,\r\n2. define a default language you'll use when,\r\na. there is no language provided (localhost/cms/users),\r\nb. the provided language is unknown (localhost/ru/cms/users).\r\n3. in your code, get the currentLanguage (ex: en) and the routableURI, a URI without any language in it (ex: cms/users): this is exactly what the purpose of the code I provided in my previous message.\r\n4. call FastRoute (indeed we're in a thread related to that repository) using the routableURI and store the currentLanguage somewhere so that you'll be able to use it in your route handler.\r\n\r\nI hope I was clear enough and good luck to you!"}}
{"actor":{"display_login":"aromot"}}