-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Roy Yu
committed
May 17, 2019
1 parent
e3d78ba
commit 259ec4d
Showing
5 changed files
with
75 additions
and
16 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
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,40 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { IntlProvider, addLocaleData } from 'react-intl' | ||
|
||
// This is react-intl locale data | ||
import en from 'react-intl/locale-data/en' | ||
|
||
// This is your translation files | ||
// In case you are curious about locale - https://gist.github.com/jacobbubu/1836273 | ||
import enUS from 'common/translations/en-US.json' | ||
|
||
// We are adding english here | ||
addLocaleData([...en]); | ||
|
||
// Creating a map of supported messages | ||
// It will be used in IntlProvider below | ||
const messages = { | ||
'en-US': enUS, | ||
} | ||
|
||
export default class I18NProvider extends React.PureComponent { | ||
static propTypes = { | ||
children: PropTypes.element.isRequired, | ||
} | ||
|
||
render() { | ||
// query the browser for language / locale | ||
// feel free to modify this logic to fit your need | ||
const language = navigator.language.split(/[-_]/)[0]; | ||
const locale = navigator.language; | ||
|
||
const { children } = this.props | ||
|
||
return ( | ||
<IntlProvider locale={language} messages={messages[locale]}> | ||
{ children } | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"greetings.hello": "Hello, {name}, this is a message from translations!" | ||
} |
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