This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functionality for i18n within application (#7)
- Loading branch information
Showing
83 changed files
with
10,900 additions
and
442 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 @@ | ||
module.exports = 'test-file-stub'; |
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
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
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,3 @@ | ||
import { injectIntl } from 'react-intl'; | ||
import App from './app'; | ||
export default injectIntl(App); |
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,53 @@ | ||
import React from 'react'; | ||
import { IntlProvider, addLocaleData } from 'react-intl'; | ||
import en from 'react-intl/locale-data/en'; | ||
import es from 'react-intl/locale-data/es'; | ||
import App from '../App/index'; | ||
import localeData from '../../locales/translations.json'; | ||
|
||
addLocaleData([...en, ...es]); | ||
|
||
class Entry extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.updateLocale = this.updateLocale.bind(this); | ||
|
||
// Define the user's language. Accounts for pulling this from different browsers | ||
const language = (navigator.languages && navigator.languages[0]) || | ||
navigator.language || navigator.userLanguage; | ||
|
||
this.state = { | ||
locale: language, | ||
}; | ||
} | ||
|
||
updateLocale(locale) { | ||
this.setState({ | ||
locale, | ||
}); | ||
} | ||
|
||
render() { | ||
let languageWithoutRegionCode; | ||
if (this.state.locale) { | ||
// Split locales with a region code | ||
languageWithoutRegionCode = this.state.locale.toLowerCase().split(/[_-]+/)[0]; | ||
} | ||
|
||
const messages = localeData[this.state.locale] | ||
|| localeData[languageWithoutRegionCode] | ||
|| localeData.en; | ||
|
||
return ( | ||
<IntlProvider | ||
locale={this.state.locale} | ||
defaultLocale={this.state.locale} | ||
messages={messages} | ||
> | ||
<App updateLocale={this.updateLocale} currentLocale={this.state.locale} /> | ||
</IntlProvider> | ||
); | ||
} | ||
} | ||
|
||
export default Entry; |
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
Oops, something went wrong.