Skip to content

Commit

Permalink
add IntlSampleApp
Browse files Browse the repository at this point in the history
sergei-zelinsky committed Dec 2, 2019
1 parent 680e9df commit 955ebf7
Showing 4 changed files with 147 additions and 2 deletions.
1 change: 1 addition & 0 deletions lesson-8/package.json
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-final-form": "^6.3.3",
"react-intl": "^3.8.0",
"react-redux": "^7.1.3",
"react-router-dom": "^5.1.2",
"react-scripts": "3.2.0",
16 changes: 16 additions & 0 deletions lesson-8/src/IntlSampleApp/Welcome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import {FormattedMessage} from 'react-intl';

const Welcome = ({name, tasksCount}) => (
<h3>
<FormattedMessage
id="welcome"
values={{
name,
tasksCount,
}}
/>
</h3>
);

export default Welcome;
35 changes: 35 additions & 0 deletions lesson-8/src/IntlSampleApp/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, {useState} from 'react';
import {IntlProvider} from 'react-intl';
import Welcome from './Welcome';

const messages = {
en: {
welcome:
'Hello {name}. You have {tasksCount, number} {tasksCount, plural, one {task} other {tasks}}',
},
ru: {
welcome:
'Привет, {name}. У вас {tasksCount, number} {tasksCount, plural, zero {сообщений} one {сообщение} few {сообщения} other {сообщений}}',
},
};

export default () => {
const [locale, setLocale] = useState('en');

const toggleLocale = () => {
const nextLocale = locale === 'en' ? 'ru' : 'en';

setLocale(nextLocale);
};
return (
<IntlProvider locale={locale} messages={messages[locale]}>
<h2>i18n (react-intl)</h2>

<h3>Current locale: {locale}</h3>
<button className="action-button" onClick={toggleLocale}>
Toggle Locale
</button>
<Welcome name="Steve" tasksCount={2} />
</IntlProvider>
);
};
97 changes: 95 additions & 2 deletions lesson-8/yarn.lock
Original file line number Diff line number Diff line change
@@ -846,6 +846,32 @@
version "9.0.1"
resolved "https://registry.yarnpkg.com/@csstools/normalize.css/-/normalize.css-9.0.1.tgz#c27b391d8457d1e893f1eddeaf5e5412d12ffbb5"

"@formatjs/intl-listformat@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@formatjs/intl-listformat/-/intl-listformat-1.3.0.tgz#822b7393f753fb1eab023a75351f63da3cb232b7"
dependencies:
"@formatjs/intl-utils" "^1.5.0"

"@formatjs/intl-relativetimeformat@^4.5.0":
version "4.5.0"
resolved "https://registry.yarnpkg.com/@formatjs/intl-relativetimeformat/-/intl-relativetimeformat-4.5.0.tgz#152c06d71c15ee3b41ffb351fead7873028bd445"
dependencies:
"@formatjs/intl-utils" "^1.5.0"

"@formatjs/intl-unified-numberformat@^2.1.8":
version "2.1.8"
resolved "https://registry.yarnpkg.com/@formatjs/intl-unified-numberformat/-/intl-unified-numberformat-2.1.8.tgz#524c8aec302908108fa38133434c52599e83fcb2"
dependencies:
"@formatjs/intl-utils" "^1.5.0"

"@formatjs/intl-utils@^1.5.0":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@formatjs/intl-utils/-/intl-utils-1.5.0.tgz#885f5ef7d11dae3ed65fffbae9c04c9c51830370"

"@formatjs/macro@^0.2.6":
version "0.2.6"
resolved "https://registry.yarnpkg.com/@formatjs/macro/-/macro-0.2.6.tgz#eb173658d803416a43210778b2f5c04c5a240bb6"

"@hapi/address@2.x.x":
version "2.1.4"
resolved "https://registry.yarnpkg.com/@hapi/address/-/address-2.1.4.tgz#5d67ed43f3fd41a69d4b9ff7b56e7c0d1d0a81e5"
@@ -1182,6 +1208,17 @@
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d"

"@types/hoist-non-react-statics@^3.3.1":
version "3.3.1"
resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f"
dependencies:
"@types/react" "*"
hoist-non-react-statics "^3.3.0"

"@types/invariant@^2.2.30":
version "2.2.30"
resolved "https://registry.yarnpkg.com/@types/invariant/-/invariant-2.2.30.tgz#20efa342807606ada5483731a8137cb1561e5fe9"

"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz#42995b446db9a48a11a07ec083499a860e9138ff"
@@ -1203,10 +1240,21 @@
version "7.0.3"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"

"@types/prop-types@*":
version "15.7.3"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"

"@types/q@^1.5.1":
version "1.5.2"
resolved "https://registry.yarnpkg.com/@types/q/-/q-1.5.2.tgz#690a1475b84f2a884fd07cd797c00f5f31356ea8"

"@types/react@*":
version "16.9.13"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.13.tgz#b3ea5dd443f4a680599e2abba8cc66f5e1ce0059"
dependencies:
"@types/prop-types" "*"
csstype "^2.2.0"

"@types/stack-utils@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
@@ -2745,6 +2793,10 @@ cssstyle@^1.0.0, cssstyle@^1.1.1:
dependencies:
cssom "0.3.x"

csstype@^2.2.0:
version "2.6.7"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.7.tgz#20b0024c20b6718f4eda3853a1f5a1cce7f5e4a5"

cyclist@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9"
@@ -4068,7 +4120,7 @@ hmac-drbg@^1.0.0:
minimalistic-assert "^1.0.0"
minimalistic-crypto-utils "^1.0.1"

hoist-non-react-statics@^3.1.0, hoist-non-react-statics@^3.3.0:
hoist-non-react-statics@^3.1.0, hoist-non-react-statics@^3.3.0, hoist-non-react-statics@^3.3.1:
version "3.3.1"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz#101685d3aff3b23ea213163f6e8e12f4f111e19f"
dependencies:
@@ -4368,7 +4420,26 @@ internal-ip@^4.2.0:
default-gateway "^4.2.0"
ipaddr.js "^1.9.0"

invariant@^2.2.2, invariant@^2.2.4:
intl-format-cache@^4.2.12:
version "4.2.12"
resolved "https://registry.yarnpkg.com/intl-format-cache/-/intl-format-cache-4.2.12.tgz#7165f25bd9dbed87b7af521463746ac62440bda6"

intl-locales-supported@^1.8.4:
version "1.8.4"
resolved "https://registry.yarnpkg.com/intl-locales-supported/-/intl-locales-supported-1.8.4.tgz#e1d19812afa50dc2e2a2b4741ceb4030522d45b1"

intl-messageformat-parser@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/intl-messageformat-parser/-/intl-messageformat-parser-3.4.0.tgz#3af6931fbd4a790d2c65aeab2ba9ea76ab14aba0"

intl-messageformat@^7.7.0:
version "7.7.0"
resolved "https://registry.yarnpkg.com/intl-messageformat/-/intl-messageformat-7.7.0.tgz#f861c2d16f92e8e5c0664465584097b967eef267"
dependencies:
intl-format-cache "^4.2.12"
intl-messageformat-parser "^3.4.0"

invariant@^2.1.1, invariant@^2.2.2, invariant@^2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
dependencies:
@@ -7216,6 +7287,24 @@ react-final-form@^6.3.3:
"@babel/runtime" "^7.4.5"
ts-essentials "^3.0.2"

react-intl@^3.8.0:
version "3.8.0"
resolved "https://registry.yarnpkg.com/react-intl/-/react-intl-3.8.0.tgz#d4e955c00a0d8c2acace0d9e5a0ef152336c60ff"
dependencies:
"@formatjs/intl-listformat" "^1.3.0"
"@formatjs/intl-relativetimeformat" "^4.5.0"
"@formatjs/intl-unified-numberformat" "^2.1.8"
"@formatjs/macro" "^0.2.6"
"@types/hoist-non-react-statics" "^3.3.1"
"@types/invariant" "^2.2.30"
hoist-non-react-statics "^3.3.1"
intl-format-cache "^4.2.12"
intl-locales-supported "^1.8.4"
intl-messageformat "^7.7.0"
intl-messageformat-parser "^3.4.0"
invariant "^2.1.1"
shallow-equal "^1.1.0"

react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4, react-is@^16.9.0:
version "16.12.0"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.12.0.tgz#2cc0fe0fba742d97fd527c42a13bec4eeb06241c"
@@ -7930,6 +8019,10 @@ shallow-clone@^3.0.0:
dependencies:
kind-of "^6.0.2"

shallow-equal@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/shallow-equal/-/shallow-equal-1.2.0.tgz#fd828d2029ff4e19569db7e19e535e94e2d1f5cc"

shebang-command@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea"

0 comments on commit 955ebf7

Please sign in to comment.