-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from edx/efischer/export_all_locales
locale data scripts are no longer passed in DOM
- Loading branch information
Showing
9 changed files
with
48 additions
and
35 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
import Enzyme from 'enzyme'; | ||
|
||
document.write('<!doctype html><html><body><script type="application/json" id="SFE_i18n_messages">{"testMessage": "Hola"}</script><script type="application/json" id="SFE_i18n_localeScript">{"locale": "fr","data": ""}</script><div id="root" class="SFE"></div></body></html>'); | ||
document.write('<!doctype html><html><body><script type="application/json" id="SFE_i18n_data">{"locale": "fr", "messages": {"testMessage": "Hola"}}</script><div id="root" class="SFE"></div></body></html>'); | ||
Enzyme.configure({ adapter: new Adapter() }); |
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
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 |
---|---|---|
@@ -1,25 +1,22 @@ | ||
import enLocaleData from 'react-intl/locale-data/en'; | ||
import { addLocaleData } from 'react-intl'; | ||
|
||
const loadI18nDomData = () => { | ||
const retDict = {}; | ||
let localeData; | ||
import localeDataMap from '../../data/i18n/locales/json/currentlySupportedLangs'; | ||
|
||
const loadI18nDomData = () => { | ||
try { | ||
const domDefinedLocaleData = JSON.parse(document.getElementById('SFE_i18n_localeScript').innerHTML); | ||
localeData = domDefinedLocaleData.data; | ||
retDict.locale = domDefinedLocaleData.locale; | ||
retDict.messages = JSON.parse(document.getElementById('SFE_i18n_messages').innerHTML); | ||
const domDefinedData = JSON.parse(document.getElementById('SFE_i18n_data').innerHTML); | ||
const localeData = localeDataMap[domDefinedData.locale]; | ||
addLocaleData(localeData); | ||
return domDefinedData; | ||
} catch (err) { | ||
// fail back to default english values if any errors | ||
localeData = enLocaleData; | ||
retDict.locale = 'en'; | ||
// an empty dict will yield defaultMessages on fallback, no problem there | ||
retDict.messages = {}; | ||
addLocaleData(enLocaleData); | ||
return { | ||
locale: 'en', | ||
messages: {}, | ||
}; | ||
} | ||
addLocaleData(localeData); | ||
|
||
return retDict; | ||
}; | ||
|
||
export default loadI18nDomData; |
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