{"action":"created","issue":{"url":"https://api.github.com/repos/jooby-project/jooby/issues/273","repository_url":"https://api.github.com/repos/jooby-project/jooby","labels_url":"https://api.github.com/repos/jooby-project/jooby/issues/273/labels{/name}","comments_url":"https://api.github.com/repos/jooby-project/jooby/issues/273/comments","events_url":"https://api.github.com/repos/jooby-project/jooby/issues/273/events","html_url":"https://github.com/jooby-project/jooby/issues/273","id":134066058,"number":273,"title":"Conform locale matching with RFC4647","user":{"login":"authchir","id":320458,"avatar_url":"https://avatars.githubusercontent.com/u/320458?v=3","gravatar_id":"","url":"https://api.github.com/users/authchir","html_url":"https://github.com/authchir","followers_url":"https://api.github.com/users/authchir/followers","following_url":"https://api.github.com/users/authchir/following{/other_user}","gists_url":"https://api.github.com/users/authchir/gists{/gist_id}","starred_url":"https://api.github.com/users/authchir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/authchir/subscriptions","organizations_url":"https://api.github.com/users/authchir/orgs","repos_url":"https://api.github.com/users/authchir/repos","events_url":"https://api.github.com/users/authchir/events{/privacy}","received_events_url":"https://api.github.com/users/authchir/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jooby-project/jooby/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/jooby-project/jooby/milestones/31","html_url":"https://github.com/jooby-project/jooby/milestones/0.15.0","labels_url":"https://api.github.com/repos/jooby-project/jooby/milestones/31/labels","id":1571697,"number":31,"title":"0.15.0","description":"","creator":{"login":"jknack","id":1301129,"avatar_url":"https://avatars.githubusercontent.com/u/1301129?v=3","gravatar_id":"","url":"https://api.github.com/users/jknack","html_url":"https://github.com/jknack","followers_url":"https://api.github.com/users/jknack/followers","following_url":"https://api.github.com/users/jknack/following{/other_user}","gists_url":"https://api.github.com/users/jknack/gists{/gist_id}","starred_url":"https://api.github.com/users/jknack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jknack/subscriptions","organizations_url":"https://api.github.com/users/jknack/orgs","repos_url":"https://api.github.com/users/jknack/repos","events_url":"https://api.github.com/users/jknack/events{/privacy}","received_events_url":"https://api.github.com/users/jknack/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":12,"state":"closed","created_at":"2016-02-09T00:33:32Z","updated_at":"2016-03-11T17:47:32Z","due_on":null,"closed_at":"2016-02-22T19:28:48Z"},"comments":9,"created_at":"2016-02-16T18:54:10Z","updated_at":"2016-03-11T19:14:00Z","closed_at":null,"body":"I just got strange results from the `Result.locale()` function and took a quick look at the implementation. If my understanding is correct, it seems that the [current locale detection algorithm][1] is a little naïve:\r\n\r\n1. Set the default locale from the configuration file as the request's locale.\r\n2. If the header `Accept-Language` is present, split naïvely the value to create a new locale.\r\n\r\nIt would be interesting if the locale matching was conforming to the [RFC4647][2], wich is already implemented in Java's [`Locale`][3].\r\n\r\n[1]:https://github.com/jooby-project/jooby/blob/3d2e2994ff09979fddbec44ea91b90e623928a8e/jooby/src/main/java/org/jooby/internal/RequestImpl.java#L101-L102\r\n[2]:http://tools.ietf.org/html/rfc4647\r\n[3]:https://docs.oracle.com/javase/8/docs/api/java/util/Locale.html#LocaleMatching"},"comment":{"url":"https://api.github.com/repos/jooby-project/jooby/issues/comments/195504326","html_url":"https://github.com/jooby-project/jooby/issues/273#issuecomment-195504326","issue_url":"https://api.github.com/repos/jooby-project/jooby/issues/273","id":195504326,"user":{"login":"authchir","id":320458,"avatar_url":"https://avatars.githubusercontent.com/u/320458?v=3","gravatar_id":"","url":"https://api.github.com/users/authchir","html_url":"https://github.com/authchir","followers_url":"https://api.github.com/users/authchir/followers","following_url":"https://api.github.com/users/authchir/following{/other_user}","gists_url":"https://api.github.com/users/authchir/gists{/gist_id}","starred_url":"https://api.github.com/users/authchir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/authchir/subscriptions","organizations_url":"https://api.github.com/users/authchir/orgs","repos_url":"https://api.github.com/users/authchir/repos","events_url":"https://api.github.com/users/authchir/events{/privacy}","received_events_url":"https://api.github.com/users/authchir/received_events","type":"User","site_admin":false},"created_at":"2016-03-11T19:14:00Z","updated_at":"2016-03-11T19:14:00Z","body":"> what about the other method we introduced already\r\n> [...]\r\n> is still useful?\r\n\r\nYou are right. While the `List<Locale> locales()` method would work for a resource available in all locales supported in the application configuration, one can imagine that some specific resource could only be available in other resource-specific locales. It is a good idea to keep it.\r\n\r\n> also, what if we have a empty Accept header and/or a value that isn't support by our app?\r\n> what will be the output of the new locales() method?\r\n\r\nAssuming the following configuration: `app.lang = \"fr-CA, fr-FR, en, en-CA, en-GB, en-US, de\"`.\r\nThe default locale being the first element of the list.\r\n\r\nThe former situation is twofold:\r\n\r\n - The header is absent.\r\n - The header contains some invalid value (e.g. \"\", \"1234\", \"Lorem ipsum\", etc.).\r\n\r\nWe handle both cases in the same way:\r\n\r\n```\r\nreq.locales() == Collections.EMPTY_LIST\r\nreq.locale() == Optional.none()\r\nreq.localeOrDefault() == Locale.forLanguageTag(\"fr-CA\")\r\n```\r\n\r\nThe later corresponds the following case in my tests:\r\n\r\n```\r\n$ java Main \"es\"\r\nFilter: []\r\nLookup: null\r\n```\r\n\r\nSpanish not being a supported locale, the returned list is empty, thus:\r\n\r\n```\r\nreq.locales() == Collections.EMPTY_LIST\r\nreq.locale() == Optional.none()\r\nreq.localeOrDefault() == Locale.forLanguageTag(\"fr-CA\")\r\n```"}}