{"action":"created","issue":{"url":"https://api.github.com/repos/zendframework/zend-expressive/issues/226","labels_url":"https://api.github.com/repos/zendframework/zend-expressive/issues/226/labels{/name}","comments_url":"https://api.github.com/repos/zendframework/zend-expressive/issues/226/comments","events_url":"https://api.github.com/repos/zendframework/zend-expressive/issues/226/events","html_url":"https://github.com/zendframework/zend-expressive/issues/226","id":121862022,"number":226,"title":"[Cookbook] How to setup localization","user":{"login":"RalfEggert","id":1562549,"avatar_url":"https://avatars.githubusercontent.com/u/1562549?v=3","gravatar_id":"","url":"https://api.github.com/users/RalfEggert","html_url":"https://github.com/RalfEggert","followers_url":"https://api.github.com/users/RalfEggert/followers","following_url":"https://api.github.com/users/RalfEggert/following{/other_user}","gists_url":"https://api.github.com/users/RalfEggert/gists{/gist_id}","starred_url":"https://api.github.com/users/RalfEggert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RalfEggert/subscriptions","organizations_url":"https://api.github.com/users/RalfEggert/orgs","repos_url":"https://api.github.com/users/RalfEggert/repos","events_url":"https://api.github.com/users/RalfEggert/events{/privacy}","received_events_url":"https://api.github.com/users/RalfEggert/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/zendframework/zend-expressive/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-12-12T15:35:18Z","updated_at":"2015-12-14T11:28:12Z","closed_at":null,"body":"A suggestion for the cookbook: How to setup the localization?\r\n\r\nLet's say in the routing is a `lang` parameter which defines the current language. This should be used to set the locale for the application. How can this be archieved? Are their multiple ways to handle this? Which way is the most recommended way?"},"comment":{"url":"https://api.github.com/repos/zendframework/zend-expressive/issues/comments/164414733","html_url":"https://github.com/zendframework/zend-expressive/issues/226#issuecomment-164414733","issue_url":"https://api.github.com/repos/zendframework/zend-expressive/issues/226","id":164414733,"user":{"login":"RalfEggert","id":1562549,"avatar_url":"https://avatars.githubusercontent.com/u/1562549?v=3","gravatar_id":"","url":"https://api.github.com/users/RalfEggert","html_url":"https://github.com/RalfEggert","followers_url":"https://api.github.com/users/RalfEggert/followers","following_url":"https://api.github.com/users/RalfEggert/following{/other_user}","gists_url":"https://api.github.com/users/RalfEggert/gists{/gist_id}","starred_url":"https://api.github.com/users/RalfEggert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RalfEggert/subscriptions","organizations_url":"https://api.github.com/users/RalfEggert/orgs","repos_url":"https://api.github.com/users/RalfEggert/repos","events_url":"https://api.github.com/users/RalfEggert/events{/privacy}","received_events_url":"https://api.github.com/users/RalfEggert/received_events","type":"User","site_admin":false},"created_at":"2015-12-14T11:28:12Z","updated_at":"2015-12-14T11:28:12Z","body":"Well, I came up now with this class:\r\n\r\n```\r\nnamespace Application\\I18n;\r\n\r\nuse Locale;\r\nuse Zend\\Expressive\\Router\\RouteResult;\r\nuse Zend\\Expressive\\Router\\RouteResultObserverInterface;\r\n\r\nclass LocalizationObserver implements RouteResultObserverInterface\r\n{\r\n    public function update(RouteResult $result)\r\n    {\r\n        if ($result->isFailure()) {\r\n            return;\r\n        }\r\n\r\n        $matchedParams = $result->getMatchedParams();\r\n\r\n        if (isset($matchedParams['lang'])) {\r\n            Locale::setDefault($matchedParams['lang']);\r\n        } else {\r\n            Locale::setDefault('de_DE');\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nI configured it in the `dependencies.global.php` and attached it to my app in the `index.php`.\r\n\r\n```\r\nuse Application\\I18n\\LocalizationObserver;\r\n\r\n[...]\r\n\r\n$app = $container->get('Zend\\Expressive\\Application');\r\n$app->attachRouteResultObserver(\r\n    $container->get(LocalizationObserver::class)\r\n);\r\n$app->run();\r\n```\r\n\r\nI don't know if this is a good practice or rather a bad one? \r\n\r\nAnyway would be nice If I don't need to amend the `index.php`. But is writing my own factory for key `Zend\\Expressive\\Application` the best way to do it? Or would a config param make sense?"}}