-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
680e9df
commit 955ebf7
Showing
4 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters