Skip to content

Commit

Permalink
feat(annotations): simplified intl for annotations
Browse files Browse the repository at this point in the history
* Send over messages from Preview
  • Loading branch information
mickr committed Feb 9, 2020
1 parent 863cb00 commit 491f3da
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 23 deletions.
4 changes: 1 addition & 3 deletions src/lib/__tests__/i18n-test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { IntlProvider } from 'react-intl';
import i18n from '../i18n';

describe('i18n', () => {
it('should return an intl provider object', () => {
const intl = i18n.createAnnotatorIntl();
expect(intl.provider).to.be.an.instanceof(IntlProvider);
expect(intl.messages).to.be.an('object');
expect(intl.language).to.equal('en-US');
expect(intl.intlLocaleData).to.be.an('array');
});
});
21 changes: 4 additions & 17 deletions src/lib/i18n.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { IntlProvider, addLocaleData } from 'react-intl';
import intlLocaleData from 'react-intl-locale-data'; // eslint-disable-line

// TODO @mickryan remove after we upgrade the annotations version
let annotationMessages;
let annotationMessages = {};

try {
annotationMessages = require('box-annotations-messages'); // eslint-disable-line
} catch (e) {
annotationMessages = {};
}
annotationMessages = require('box-annotations-messages').default; // eslint-disable-line
} catch (e) {} // eslint-disable-line

const language = __LANGUAGE__ || 'en-US'; // eslint-disable-line

Expand All @@ -19,17 +14,9 @@ const language = __LANGUAGE__ || 'en-US'; // eslint-disable-line
* @return {Object}
*/
const createAnnotatorIntl = () => {
addLocaleData(intlLocaleData);
return {
intlLocaleData,
messages: annotationMessages,
language,
provider: new IntlProvider(
{
locale: language.substr(0, language.indexOf('-')),
messages: annotationMessages,
},
{},
),
};
};

Expand Down
4 changes: 1 addition & 3 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable no-unused-expressions */
import EventEmitter from 'events';
import { IntlProvider } from 'react-intl';
import BaseViewer from '../BaseViewer';
import Browser from '../../Browser';
import RepStatus from '../../RepStatus';
Expand Down Expand Up @@ -1386,9 +1385,8 @@ describe('lib/viewers/BaseViewer', () => {
expect(combinedOptions.location).to.deep.equal({ locale: 'en-US' });
expect(combinedOptions.randomOption).to.equal('derp');
expect(combinedOptions.localizedStrings).to.not.be.undefined;
expect(combinedOptions.intl.provider).to.be.an.instanceof(IntlProvider);
expect(combinedOptions.intl.language).to.equal('en-US');
expect(combinedOptions.intl.intlLocaleData).to.be.an('array');
expect(combinedOptions.intl.messages).to.be.an('object');
});
});

Expand Down

0 comments on commit 491f3da

Please sign in to comment.