diff --git a/package-lock.json b/package-lock.json index cd0478754..b3348e2ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1225,6 +1225,11 @@ "tslib": "^1" } }, + "@formatjs/intl-relativetimeformat": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/@formatjs/intl-relativetimeformat/-/intl-relativetimeformat-2.6.3.tgz", + "integrity": "sha512-sb3PcbTSNQfnL4HM2XKedt8Oopf2EwaoxyjeMbgvje6x1zQuf1oTAidLHT65Dkox7hfSql8ZjpAqWqnHJsLN9w==" + }, "@heroku-cli/color": { "version": "1.1.14", "resolved": "https://registry.npmjs.org/@heroku-cli/color/-/color-1.1.14.tgz", @@ -2826,6 +2831,11 @@ "integrity": "sha512-ZiSCqW8j9/gQCYixz1nMhyCprSGh3rwdyX+FHAzEN+bMCmc7yCYjNutl6jvMYSxSIGeL0CLEXPM8Nlk2lE0t5w==", "dev": true }, + "@types/invariant": { + "version": "2.2.30", + "resolved": "https://registry.npmjs.org/@types/invariant/-/invariant-2.2.30.tgz", + "integrity": "sha512-98fB+yo7imSD2F7PF7GIpELNgtLNgo5wjivu0W5V4jx+KVVJxo6p/qN4zdzSTBWy4/sN3pPyXwnhRSD28QX+ag==" + }, "@types/istanbul-lib-coverage": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz", @@ -11103,6 +11113,30 @@ "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.2.0.tgz", "integrity": "sha512-mT34yGKMNceBQUoVn7iCDKDntA7SC6gycMAWzGx1z/CMCTV7b2AAtXlo3nRyHZ1FelRkQbQjprHSYGwzLtkVbw==" }, + "intl-format-cache": { + "version": "4.1.10", + "resolved": "https://registry.npmjs.org/intl-format-cache/-/intl-format-cache-4.1.10.tgz", + "integrity": "sha512-7NqorxPNPuhbtwlXe71Dbjh9NlLvkoUymCI2AS/cyIsG7wYr27x9E/h4P16vftHwsTOjiDIjM/oGukddxgcz3A==" + }, + "intl-locales-supported": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/intl-locales-supported/-/intl-locales-supported-1.4.5.tgz", + "integrity": "sha512-D7oriM5x46rd7kNlSW0f9noIBegFr3ReIM6xlMpwH4lfIPD/zvBelPlCjR10IK16boGJG9lKccOvRAM8wzpbrA==" + }, + "intl-messageformat": { + "version": "6.1.5", + "resolved": "https://registry.npmjs.org/intl-messageformat/-/intl-messageformat-6.1.5.tgz", + "integrity": "sha512-Ae/3PwnShCkDtnPvx9FLlBj1xiooa5NeeFZBizOQZZ/iaLt8IvgkPCdadkOF3f++FWDOBVtP5RszhMkJQKqmng==", + "requires": { + "intl-format-cache": "^4.1.10", + "intl-messageformat-parser": "^3.0.7" + } + }, + "intl-messageformat-parser": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/intl-messageformat-parser/-/intl-messageformat-parser-3.0.7.tgz", + "integrity": "sha512-L16VbbV3NFaiZV65XwOIH9fBe52TS2EkOR0k8Y4ratsgTE7KPEbcUCUrz/iEQwJo7BcWY4ohkZbeYZRgAiPR1Q==" + }, "into-stream": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/into-stream/-/into-stream-3.1.0.tgz", @@ -16077,6 +16111,25 @@ "once": "^1.4.0" } }, + "react-intl": { + "version": "3.1.7", + "resolved": "https://registry.npmjs.org/react-intl/-/react-intl-3.1.7.tgz", + "integrity": "sha512-bsEQETQ9Ihk0a+z0WDdZhFRlP5MhbIfZJFG1D8IeYu7u7Y0tRYjLt2VDHEUBGsi7OIbTOPl2VTMXtRsb6BHP/Q==", + "requires": { + "@formatjs/intl-relativetimeformat": "^2.6.3", + "@types/hoist-non-react-statics": "^3.3.1", + "@types/invariant": "^2.2.30", + "@types/react": "^16.0.0", + "hoist-non-react-statics": "^3.3.0", + "intl-format-cache": "^4.1.10", + "intl-locales-supported": "^1.4.5", + "intl-messageformat": "^6.1.5", + "intl-messageformat-parser": "^3.0.7", + "invariant": "^2.1.1", + "react": "^16.3.0", + "shallow-equal": "^1.1.0" + } + }, "react-is": { "version": "16.9.0", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.9.0.tgz", @@ -17243,8 +17296,7 @@ "shallow-equal": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/shallow-equal/-/shallow-equal-1.2.0.tgz", - "integrity": "sha512-Z21pVxR4cXsfwpMKMhCEIO1PCi5sp7KEp+CmOpBQ+E8GpHwKOw2sEzk7sgblM3d/j4z4gakoWEoPcjK0VJQogA==", - "dev": true + "integrity": "sha512-Z21pVxR4cXsfwpMKMhCEIO1PCi5sp7KEp+CmOpBQ+E8GpHwKOw2sEzk7sgblM3d/j4z4gakoWEoPcjK0VJQogA==" }, "shallowequal": { "version": "1.1.0", diff --git a/package.json b/package.json index 075fbf8bb..37538217f 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "react-helmet": "^5.2.1", "react-infinite-scroller": "^1.2.4", "react-inlinesvg": "^0.8.4", + "react-intl": "^3.1.7", "react-jss": "^8.6.1", "react-moment": "^0.7.9", "react-router": "^5.0.1", diff --git a/src/components/Locale/Locale.tsx b/src/components/Locale/Locale.tsx index d1d4fd023..bcc5fb7b7 100644 --- a/src/components/Locale/Locale.tsx +++ b/src/components/Locale/Locale.tsx @@ -1,11 +1,19 @@ import React from "react"; +import { IntlProvider } from "react-intl"; -export const LocaleContext = React.createContext("en"); +export type LocaleContextType = string; +export const LocaleContext = React.createContext("en"); const { Consumer: LocaleConsumer, Provider } = LocaleContext; const LocaleProvider = ({ children }) => { - return {children}; + const [locale] = React.useState(navigator.language); + + return ( + + {children} + + ); }; export { LocaleConsumer, LocaleProvider }; diff --git a/src/storybook/Decorator.tsx b/src/storybook/Decorator.tsx index 573cde8b1..8a2c7863c 100644 --- a/src/storybook/Decorator.tsx +++ b/src/storybook/Decorator.tsx @@ -1,25 +1,28 @@ import React from "react"; +import { LocaleProvider } from "@saleor/components/Locale"; import { Provider as DateProvider } from "../components/Date/DateContext"; import { MessageManager } from "../components/messages"; import ThemeProvider from "../components/Theme"; import { TimezoneProvider } from "../components/Timezone"; export const Decorator = storyFn => ( - - - - -
- {storyFn()} -
-
-
-
-
+ + + + + +
+ {storyFn()} +
+
+
+
+
+
); export default Decorator;