Skip to content

Commit

Permalink
fix(intl): Polyfill Intl on Safari (react-boilerplate#793)
Browse files Browse the repository at this point in the history
* fix(intl): polyfill for safari when clean the sample project

* fix(test): fix semicolon

* fix(intl): FormattedNumber doesn't work on Safari

* fix(intl): add polyfill when generate new lang

* fix(intl): add polyfill for safari when generate new lang

* fix duplicate

Closes react-boilerplate#791
  • Loading branch information
chaintng authored and mxstbr committed Jul 29, 2016
1 parent c2fea3f commit da3e502
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ if (module.hot) {

// Chunked polyfill for browsers without Intl support
if (!window.Intl) {
System.import('intl').then(() => render(translationMessages));
Promise.all([
System.import('intl'),
System.import('intl/locale-data/jsonp/en.js'),
System.import('intl/locale-data/jsonp/de.js'),
]).then(() => render(translationMessages));
} else {
render(translationMessages);
}
Expand Down
6 changes: 6 additions & 0 deletions internals/generators/language/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ module.exports = {
templateFile: './language/translations-json.hbs',
abortOnFail: true,
});
actions.push({
type: 'modify',
path: '../../app/app.js',
pattern: /(System\.import\('intl\/locale-data\/jsonp\/[a-z]+\.js'\),\n)(?!.*System\.import\('intl\/locale-data\/jsonp\/[a-z]+\.js'\),)/g,
templateFile: './language/polyfill-intl-locale.hbs',
});
actions.push(
() => {
const cmd = 'npm run extract-intl';
Expand Down
1 change: 1 addition & 0 deletions internals/generators/language/polyfill-intl-locale.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$1 System.import('intl/locale-data/jsonp/{{language}}.js'),
5 changes: 4 additions & 1 deletion internals/templates/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ if (module.hot) {

// Chunked polyfill for browsers without Intl support
if (!window.Intl) {
System.import('intl').then(() => render(translationMessages));
Promise.all([
System.import('intl'),
System.import('intl/locale-data/jsonp/en.js'),
]).then(() => render(translationMessages));
} else {
render(translationMessages);
}
Expand Down

0 comments on commit da3e502

Please sign in to comment.