{"action":"created","comment":{"url":"https://api.github.com/repos/alakarteio/k-intl/pulls/comments/165924572","pull_request_review_id":93933618,"id":165924572,"diff_hunk":"@@ -1,15 +1,27 @@\n-import { get, template } from 'lodash'\n+import { get } from 'lodash'\n+import IntlMessageFormat from 'intl-messageformat'\n+import defaultLocaleData from './en'\n+import { addLocaleData } from './utils'\n \n-const interpolate = /{{([\\s\\S]+?)}}/g\n const defaultLabel = {}\n+const browserLanguage = window.navigator.language || window.navigator.browserLanguage\n+/* add default locale on startup, import on src folder */\n+addLocaleData(defaultLocaleData)\n \n-export default locale => (config, componentProps) =>\n+export const formatter =\n+  (lang, label = '', customFormat) => new IntlMessageFormat(label, lang, customFormat)\n+\n+export default (locale, lang = browserLanguage, customFormats) => (config, componentProps) =>\n   Object\n     .keys(config)\n     .reduce((acc, curr) => {\n       const label = get(locale, config[curr])\n-      if (componentProps && componentProps[curr]) {\n-        return { ...acc, [curr]: template(label, { interpolate })(componentProps[curr]) }\n+      if (label && componentProps && componentProps[curr]) {\n+        /* use formatJS to parse message */\n+        return {\n+          ...acc,\n+          [curr]: formatter(lang, label, customFormats).format(componentProps[curr]),","path":"src/format.js","position":28,"original_position":28,"commit_id":"fdc7d46745b3c200c6e1c17a226ffe72f6844c87","original_commit_id":"fdc7d46745b3c200c6e1c17a226ffe72f6844c87","user":{"login":"guillaumecrespel","id":26094222,"avatar_url":"https://avatars3.githubusercontent.com/u/26094222?v=4","gravatar_id":"","url":"https://api.github.com/users/guillaumecrespel","html_url":"https://github.com/guillaumecrespel","followers_url":"https://api.github.com/users/guillaumecrespel/followers","following_url":"https://api.github.com/users/guillaumecrespel/following{/other_user}","gists_url":"https://api.github.com/users/guillaumecrespel/gists{/gist_id}","starred_url":"https://api.github.com/users/guillaumecrespel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guillaumecrespel/subscriptions","organizations_url":"https://api.github.com/users/guillaumecrespel/orgs","repos_url":"https://api.github.com/users/guillaumecrespel/repos","events_url":"https://api.github.com/users/guillaumecrespel/events{/privacy}","received_events_url":"https://api.github.com/users/guillaumecrespel/received_events","type":"User","site_admin":false},"body":"I was wondering, but the constructor of `IntlMessageFormat` take the `message` and it is mandatory.\r\n\r\nDo you have any idea to cache this ?","created_at":"2018-02-05T09:56:59Z","updated_at":"2018-02-05T09:56:59Z","html_url":"https://github.com/alakarteio/k-intl/pull/4#discussion_r165924572","pull_request_url":"https://api.github.com/repos/alakarteio/k-intl/pulls/4","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/alakarteio/k-intl/pulls/comments/165924572"},"html":{"href":"https://github.com/alakarteio/k-intl/pull/4#discussion_r165924572"},"pull_request":{"href":"https://api.github.com/repos/alakarteio/k-intl/pulls/4"}},"in_reply_to_id":165899350},"pull_request":{"url":"https://api.github.com/repos/alakarteio/k-intl/pulls/4","id":166640449,"html_url":"https://github.com/alakarteio/k-intl/pull/4","diff_url":"https://github.com/alakarteio/k-intl/pull/4.diff","patch_url":"https://github.com/alakarteio/k-intl/pull/4.patch","issue_url":"https://api.github.com/repos/alakarteio/k-intl/issues/4","number":4,"state":"open","locked":false,"title":":sparkles: add formatJS","user":{"login":"guillaumecrespel","id":26094222,"avatar_url":"https://avatars3.githubusercontent.com/u/26094222?v=4","gravatar_id":"","url":"https://api.github.com/users/guillaumecrespel","html_url":"https://github.com/guillaumecrespel","followers_url":"https://api.github.com/users/guillaumecrespel/followers","following_url":"https://api.github.com/users/guillaumecrespel/following{/other_user}","gists_url":"https://api.github.com/users/guillaumecrespel/gists{/gist_id}","starred_url":"https://api.github.com/users/guillaumecrespel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guillaumecrespel/subscriptions","organizations_url":"https://api.github.com/users/guillaumecrespel/orgs","repos_url":"https://api.github.com/users/guillaumecrespel/repos","events_url":"https://api.github.com/users/guillaumecrespel/events{/privacy}","received_events_url":"https://api.github.com/users/guillaumecrespel/received_events","type":"User","site_admin":false},"body":"Add formatJS dependency.\r\n\r\nRetrieve config on store : \r\n```es6\r\nconst store = {\r\n  config: {\r\n    lang: 'fr-FR',\r\n    locale: {\r\n      common: {\r\n        param: 'param1',\r\n      },\r\n    },\r\n    formats: {\r\n      number: {\r\n        usd: { style: 'currency', currency: 'USD' },\r\n      },\r\n    },\r\n  },\r\n}\r\n```","created_at":"2018-02-01T20:14:48Z","updated_at":"2018-02-05T09:56:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"42690d8ce8e17c011f0672d995a674452ec4dd6e","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"milestone":null,"commits_url":"https://api.github.com/repos/alakarteio/k-intl/pulls/4/commits","review_comments_url":"https://api.github.com/repos/alakarteio/k-intl/pulls/4/comments","review_comment_url":"https://api.github.com/repos/alakarteio/k-intl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alakarteio/k-intl/issues/4/comments","statuses_url":"https://api.github.com/repos/alakarteio/k-intl/statuses/fdc7d46745b3c200c6e1c17a226ffe72f6844c87","head":{"label":"alakarteio:formatjs","ref":"formatjs","sha":"fdc7d46745b3c200c6e1c17a226ffe72f6844c87","user":{"login":"alakarteio","id":26111459,"avatar_url":"https://avatars2.githubusercontent.com/u/26111459?v=4","gravatar_id":"","url":"https://api.github.com/users/alakarteio","html_url":"https://github.com/alakarteio","followers_url":"https://api.github.com/users/alakarteio/followers","following_url":"https://api.github.com/users/alakarteio/following{/other_user}","gists_url":"https://api.github.com/users/alakarteio/gists{/gist_id}","starred_url":"https://api.github.com/users/alakarteio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alakarteio/subscriptions","organizations_url":"https://api.github.com/users/alakarteio/orgs","repos_url":"https://api.github.com/users/alakarteio/repos","events_url":"https://api.github.com/users/alakarteio/events{/privacy}","received_events_url":"https://api.github.com/users/alakarteio/received_events","type":"Organization","site_admin":false},"repo":{"id":118772168,"name":"k-intl","full_name":"alakarteio/k-intl","owner":{"login":"alakarteio","id":26111459,"avatar_url":"https://avatars2.githubusercontent.com/u/26111459?v=4","gravatar_id":"","url":"https://api.github.com/users/alakarteio","html_url":"https://github.com/alakarteio","followers_url":"https://api.github.com/users/alakarteio/followers","following_url":"https://api.github.com/users/alakarteio/following{/other_user}","gists_url":"https://api.github.com/users/alakarteio/gists{/gist_id}","starred_url":"https://api.github.com/users/alakarteio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alakarteio/subscriptions","organizations_url":"https://api.github.com/users/alakarteio/orgs","repos_url":"https://api.github.com/users/alakarteio/repos","events_url":"https://api.github.com/users/alakarteio/events{/privacy}","received_events_url":"https://api.github.com/users/alakarteio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alakarteio/k-intl","description":"Format and translate your texts","fork":false,"url":"https://api.github.com/repos/alakarteio/k-intl","forks_url":"https://api.github.com/repos/alakarteio/k-intl/forks","keys_url":"https://api.github.com/repos/alakarteio/k-intl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alakarteio/k-intl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alakarteio/k-intl/teams","hooks_url":"https://api.github.com/repos/alakarteio/k-intl/hooks","issue_events_url":"https://api.github.com/repos/alakarteio/k-intl/issues/events{/number}","events_url":"https://api.github.com/repos/alakarteio/k-intl/events","assignees_url":"https://api.github.com/repos/alakarteio/k-intl/assignees{/user}","branches_url":"https://api.github.com/repos/alakarteio/k-intl/branches{/branch}","tags_url":"https://api.github.com/repos/alakarteio/k-intl/tags","blobs_url":"https://api.github.com/repos/alakarteio/k-intl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alakarteio/k-intl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alakarteio/k-intl/git/refs{/sha}","trees_url":"https://api.github.com/repos/alakarteio/k-intl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alakarteio/k-intl/statuses/{sha}","languages_url":"https://api.github.com/repos/alakarteio/k-intl/languages","stargazers_url":"https://api.github.com/repos/alakarteio/k-intl/stargazers","contributors_url":"https://api.github.com/repos/alakarteio/k-intl/contributors","subscribers_url":"https://api.github.com/repos/alakarteio/k-intl/subscribers","subscription_url":"https://api.github.com/repos/alakarteio/k-intl/subscription","commits_url":"https://api.github.com/repos/alakarteio/k-intl/commits{/sha}","git_commits_url":"https://api.github.com/repos/alakarteio/k-intl/git/commits{/sha}","comments_url":"https://api.github.com/repos/alakarteio/k-intl/comments{/number}","issue_comment_url":"https://api.github.com/repos/alakarteio/k-intl/issues/comments{/number}","contents_url":"https://api.github.com/repos/alakarteio/k-intl/contents/{+path}","compare_url":"https://api.github.com/repos/alakarteio/k-intl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alakarteio/k-intl/merges","archive_url":"https://api.github.com/repos/alakarteio/k-intl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alakarteio/k-intl/downloads","issues_url":"https://api.github.com/repos/alakarteio/k-intl/issues{/number}","pulls_url":"https://api.github.com/repos/alakarteio/k-intl/pulls{/number}","milestones_url":"https://api.github.com/repos/alakarteio/k-intl/milestones{/number}","notifications_url":"https://api.github.com/repos/alakarteio/k-intl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alakarteio/k-intl/labels{/name}","releases_url":"https://api.github.com/repos/alakarteio/k-intl/releases{/id}","deployments_url":"https://api.github.com/repos/alakarteio/k-intl/deployments","created_at":"2018-01-24T13:55:18Z","updated_at":"2018-01-24T21:40:49Z","pushed_at":"2018-02-04T22:02:45Z","git_url":"git://github.com/alakarteio/k-intl.git","ssh_url":"git@github.com:alakarteio/k-intl.git","clone_url":"https://github.com/alakarteio/k-intl.git","svn_url":"https://github.com/alakarteio/k-intl","homepage":null,"size":27,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"alakarteio:master","ref":"master","sha":"449fd988ac035f9317ec8f5c6996471966e201a9","user":{"login":"alakarteio","id":26111459,"avatar_url":"https://avatars2.githubusercontent.com/u/26111459?v=4","gravatar_id":"","url":"https://api.github.com/users/alakarteio","html_url":"https://github.com/alakarteio","followers_url":"https://api.github.com/users/alakarteio/followers","following_url":"https://api.github.com/users/alakarteio/following{/other_user}","gists_url":"https://api.github.com/users/alakarteio/gists{/gist_id}","starred_url":"https://api.github.com/users/alakarteio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alakarteio/subscriptions","organizations_url":"https://api.github.com/users/alakarteio/orgs","repos_url":"https://api.github.com/users/alakarteio/repos","events_url":"https://api.github.com/users/alakarteio/events{/privacy}","received_events_url":"https://api.github.com/users/alakarteio/received_events","type":"Organization","site_admin":false},"repo":{"id":118772168,"name":"k-intl","full_name":"alakarteio/k-intl","owner":{"login":"alakarteio","id":26111459,"avatar_url":"https://avatars2.githubusercontent.com/u/26111459?v=4","gravatar_id":"","url":"https://api.github.com/users/alakarteio","html_url":"https://github.com/alakarteio","followers_url":"https://api.github.com/users/alakarteio/followers","following_url":"https://api.github.com/users/alakarteio/following{/other_user}","gists_url":"https://api.github.com/users/alakarteio/gists{/gist_id}","starred_url":"https://api.github.com/users/alakarteio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alakarteio/subscriptions","organizations_url":"https://api.github.com/users/alakarteio/orgs","repos_url":"https://api.github.com/users/alakarteio/repos","events_url":"https://api.github.com/users/alakarteio/events{/privacy}","received_events_url":"https://api.github.com/users/alakarteio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alakarteio/k-intl","description":"Format and translate your texts","fork":false,"url":"https://api.github.com/repos/alakarteio/k-intl","forks_url":"https://api.github.com/repos/alakarteio/k-intl/forks","keys_url":"https://api.github.com/repos/alakarteio/k-intl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alakarteio/k-intl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alakarteio/k-intl/teams","hooks_url":"https://api.github.com/repos/alakarteio/k-intl/hooks","issue_events_url":"https://api.github.com/repos/alakarteio/k-intl/issues/events{/number}","events_url":"https://api.github.com/repos/alakarteio/k-intl/events","assignees_url":"https://api.github.com/repos/alakarteio/k-intl/assignees{/user}","branches_url":"https://api.github.com/repos/alakarteio/k-intl/branches{/branch}","tags_url":"https://api.github.com/repos/alakarteio/k-intl/tags","blobs_url":"https://api.github.com/repos/alakarteio/k-intl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alakarteio/k-intl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alakarteio/k-intl/git/refs{/sha}","trees_url":"https://api.github.com/repos/alakarteio/k-intl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alakarteio/k-intl/statuses/{sha}","languages_url":"https://api.github.com/repos/alakarteio/k-intl/languages","stargazers_url":"https://api.github.com/repos/alakarteio/k-intl/stargazers","contributors_url":"https://api.github.com/repos/alakarteio/k-intl/contributors","subscribers_url":"https://api.github.com/repos/alakarteio/k-intl/subscribers","subscription_url":"https://api.github.com/repos/alakarteio/k-intl/subscription","commits_url":"https://api.github.com/repos/alakarteio/k-intl/commits{/sha}","git_commits_url":"https://api.github.com/repos/alakarteio/k-intl/git/commits{/sha}","comments_url":"https://api.github.com/repos/alakarteio/k-intl/comments{/number}","issue_comment_url":"https://api.github.com/repos/alakarteio/k-intl/issues/comments{/number}","contents_url":"https://api.github.com/repos/alakarteio/k-intl/contents/{+path}","compare_url":"https://api.github.com/repos/alakarteio/k-intl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alakarteio/k-intl/merges","archive_url":"https://api.github.com/repos/alakarteio/k-intl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alakarteio/k-intl/downloads","issues_url":"https://api.github.com/repos/alakarteio/k-intl/issues{/number}","pulls_url":"https://api.github.com/repos/alakarteio/k-intl/pulls{/number}","milestones_url":"https://api.github.com/repos/alakarteio/k-intl/milestones{/number}","notifications_url":"https://api.github.com/repos/alakarteio/k-intl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alakarteio/k-intl/labels{/name}","releases_url":"https://api.github.com/repos/alakarteio/k-intl/releases{/id}","deployments_url":"https://api.github.com/repos/alakarteio/k-intl/deployments","created_at":"2018-01-24T13:55:18Z","updated_at":"2018-01-24T21:40:49Z","pushed_at":"2018-02-04T22:02:45Z","git_url":"git://github.com/alakarteio/k-intl.git","ssh_url":"git@github.com:alakarteio/k-intl.git","clone_url":"https://github.com/alakarteio/k-intl.git","svn_url":"https://github.com/alakarteio/k-intl","homepage":null,"size":27,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alakarteio/k-intl/pulls/4"},"html":{"href":"https://github.com/alakarteio/k-intl/pull/4"},"issue":{"href":"https://api.github.com/repos/alakarteio/k-intl/issues/4"},"comments":{"href":"https://api.github.com/repos/alakarteio/k-intl/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/alakarteio/k-intl/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/alakarteio/k-intl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alakarteio/k-intl/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/alakarteio/k-intl/statuses/fdc7d46745b3c200c6e1c17a226ffe72f6844c87"}},"author_association":"OWNER"}}
{"actor":{"display_login":"guillaumecrespel"}}