{"action":"closed","issue":{"url":"https://api.github.com/repos/ryandrewjohnson/react-localize-redux/issues/30","repository_url":"https://api.github.com/repos/ryandrewjohnson/react-localize-redux","labels_url":"https://api.github.com/repos/ryandrewjohnson/react-localize-redux/issues/30/labels{/name}","comments_url":"https://api.github.com/repos/ryandrewjohnson/react-localize-redux/issues/30/comments","events_url":"https://api.github.com/repos/ryandrewjohnson/react-localize-redux/issues/30/events","html_url":"https://github.com/ryandrewjohnson/react-localize-redux/issues/30","id":266785634,"number":30,"title":"Feature Request: initialize() with array of objects","user":{"login":"Landish","id":534610,"avatar_url":"https://avatars3.githubusercontent.com/u/534610?v=4","gravatar_id":"","url":"https://api.github.com/users/Landish","html_url":"https://github.com/Landish","followers_url":"https://api.github.com/users/Landish/followers","following_url":"https://api.github.com/users/Landish/following{/other_user}","gists_url":"https://api.github.com/users/Landish/gists{/gist_id}","starred_url":"https://api.github.com/users/Landish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Landish/subscriptions","organizations_url":"https://api.github.com/users/Landish/orgs","repos_url":"https://api.github.com/users/Landish/repos","events_url":"https://api.github.com/users/Landish/events{/privacy}","received_events_url":"https://api.github.com/users/Landish/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-10-19T09:57:02Z","updated_at":"2017-11-08T09:00:54Z","closed_at":"2017-11-08T09:00:54Z","author_association":"NONE","body":"Hi @ryandrewjohnson,\r\n\r\nI'm opening this issue about the topic, which I started in #21.\r\n\r\nThe _problem_ in current solution is that, you can only initialize locales with _language codes_.\r\n\r\n```js\r\nimport { initialize } from 'react-localize-redux';\r\n\r\nconst languages = ['en', 'fr', 'es'];\r\nstore.dispatch(initialize(languages));\r\n```\r\nAnd with this scenario, it is bit hard to get the _current language name_. \r\n\r\nI had to implement my own util functions to display \"English\" in a `<LocaleSwitcher />` component, which is simple dropdown with `select` tag.\r\n\r\nSomething like this:\r\n\r\n```js\r\nconst locales = [\r\n  {\r\n    code: 'en',\r\n    name: 'English',\r\n  },\r\n  {\r\n    code: 'fr',\r\n    name: 'French',\r\n  },\r\n  {\r\n    code: 'es',\r\n    name: 'Spanish',\r\n  },\r\n];\r\n\r\n// localeByCode('es') => { code: 'es', name: 'Spanish' }\r\n// this util function is used then <LocaleSwticher /> component\r\n// to display the current language name.\r\nconst localeByCode = (code, locales) => {\r\n  const locale = locales.filter(l => l.code === code)[0];\r\n  return locale ? locale : locales[0];\r\n};\r\n\r\n// => ['en', 'fr', 'es']\r\nconst localeCodes = locales.map(l => l.code);\r\nstore.dispatch(initialize(localeCodes));\r\n```\r\n\r\nWhat i'm proposing is, that to have an ability to pass an **array of objects** in `initialize` action creator.\r\n\r\nAnd the API would look something like this:\r\n\r\n```js\r\nimport { initialize } from 'react-localize-redux';\r\n\r\nconst languages = [{\r\n    code: 'en',\r\n    name: 'English',\r\n  },\r\n  {\r\n    code: 'fr',\r\n    name: 'French',\r\n  },\r\n];\r\n\r\nstore.dispatch(initialize(languages));\r\n```\r\n\r\nAlso, in this case, `getLanguages()` and `getActiveLanguage()` should return different values:\r\n\r\n```\r\n// getActiveLanguage() => { code: 'en', name: 'English', active: true } \r\n// Instead of: \r\n// getActiveLanguage() => { code: 'en', active: true }\r\n\r\n// getLanguages() => \r\n[{ code: 'en', name: 'English', active: true }, { code: 'fr', name: 'French', active: false }]\r\n// Instead of: \r\n// getLanguages() => [{ code: 'en', active: true }, { code: 'fr', active: false }]\r\n```\r\n\r\nOther actions should not be changed, as long as, they don't need to know about that `name` key."}}
{"actor":{"display_login":"Landish"}}