{"action":"opened","issue":{"url":"https://api.github.com/repos/i18next/i18next/issues/963","repository_url":"https://api.github.com/repos/i18next/i18next","labels_url":"https://api.github.com/repos/i18next/i18next/issues/963/labels{/name}","comments_url":"https://api.github.com/repos/i18next/i18next/issues/963/comments","events_url":"https://api.github.com/repos/i18next/i18next/issues/963/events","html_url":"https://github.com/i18next/i18next/issues/963","id":257399209,"number":963,"title":"Check if a language is valid","user":{"login":"TimoRuetten","id":7010059,"avatar_url":"https://avatars1.githubusercontent.com/u/7010059?v=4","gravatar_id":"","url":"https://api.github.com/users/TimoRuetten","html_url":"https://github.com/TimoRuetten","followers_url":"https://api.github.com/users/TimoRuetten/followers","following_url":"https://api.github.com/users/TimoRuetten/following{/other_user}","gists_url":"https://api.github.com/users/TimoRuetten/gists{/gist_id}","starred_url":"https://api.github.com/users/TimoRuetten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimoRuetten/subscriptions","organizations_url":"https://api.github.com/users/TimoRuetten/orgs","repos_url":"https://api.github.com/users/TimoRuetten/repos","events_url":"https://api.github.com/users/TimoRuetten/events{/privacy}","received_events_url":"https://api.github.com/users/TimoRuetten/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-09-13T14:21:25Z","updated_at":"2017-09-13T14:21:25Z","closed_at":null,"author_association":"NONE","body":"I am currently working on an express app which is using I18next. In our case we want to have the lang code in our URL like this:\r\n\r\n`/en/...` or `/en-GB/...`.\r\n\r\nIn our initialisation of I18next we are setting the whiteList and set it to `['en']` and set `nonExplicitWhitelist` to `true`. At the end our I18next setup looks like this:\r\n\r\n```\r\n...\r\nfallbackLng: 'en',\r\n    whiteList: [\r\n      'en',\r\n    ],\r\n    nonExplicitWhitelist: true,\r\n    ns: [\r\n      'ui',\r\n    ],\r\n    defaultNS: 'ui',\r\n    react: {\r\n      wait: false,\r\n      withRef: false,\r\n      bindI18n: 'languageChanged loaded',\r\n      bindStore: 'added removed',\r\n      nsMode: 'default',\r\n    },\r\n...\r\n```\r\n\r\nOur goal is now that we detect the language with the LanguageDetecter (which works great) and using the middleware so we can access the req.language property. But before we render our HTML we will check if the langCode is given in the URL. If there is no langCode given we will take req.language and do a redirect. But if smth is given we want to check if its a valid language or if not.\r\n\r\n\r\n\r\n\r\n```\r\n...\r\nconst lang = req.url.split('/')[1];\r\n  if (\r\n    lang.length &&\r\n    i18nextInstance.options.whiteList.indexOf(lang) !== -1\r\n  ) {\r\n    req.i18n.changeLanguage(lang);\r\n    next();\r\n  }\r\n...\r\n\r\n```\r\n\r\nIf our langCode now would be en-GB this would not work, because in whiteList is only en. Of course we could split the langCode with \"-\" and always use the first parameter - but I am wondering if is there a \"correct\" way of testing a valid language code for the given i18next instance or a recommended way to work with langCodes in express in combination with i18next.\r\n\r\nAs far as I understood the `nonExplicitWhitelist` it would add the localisation specifications by itself - but it does not. Maybe I am getting smth wrong ?\r\n\r\n"}}
{"actor":{"display_login":"TimoRuetten"}}