Skip to content

Commit db61662

Browse files
Change I18n to export and object like most of our other files. This will allow us to make it mockable as well
1 parent 163533a commit db61662

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

src/oceans/i18n.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@ import data from '../../i18n/oceans.json';
22
import MessageFormat from 'messageformat'
33

44
let messages;
5-
export const init = (i18n = {}) => {
5+
6+
const initI18n = (i18n = {}) => {
67
// For now, use English pluralization rules.
78
const mf = new MessageFormat('en');
89
messages = {...mf.compile(data), ...i18n};
910
};
1011

11-
export const t = (key, options) => {
12+
const t = (key, options) => {
1213
if (!messages) {
1314
throw "I18n must be initialized before calling t";
1415
}
1516
return messages[key](options);
1617
};
18+
19+
export default {
20+
initI18n,
21+
t
22+
};

src/oceans/init.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {setInitialState, setSetStateCallback} from './state';
77
import {render as renderCanvas} from './renderer';
88
import modeHelpers from './modeHelpers';
99
import soundLibrary from './models/soundLibrary';
10-
import * as I18n from './i18n';
10+
import I18n from './i18n';
1111

1212
//
1313
// Required in options:
@@ -27,7 +27,7 @@ export const initAll = function(options) {
2727

2828
soundLibrary.loadSounds();
2929

30-
I18n.init(options.i18n);
30+
I18n.initI18n(options.i18n);
3131

3232
// Set initial state for UI elements.
3333
setInitialState({

src/oceans/models/train.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {ClassType, AppMode} from '../constants';
44
import SimpleTrainer from '../../utils/SimpleTrainer';
55
import SVMTrainer from '../../utils/SVMTrainer';
66
import {generateOcean} from '../../utils/generateOcean';
7-
import * as I18n from '../i18n';
7+
import I18n from '../i18n';
88

99
const init = () => {
1010
const state = getState();

src/oceans/ui.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
faInfo,
3232
faTrash
3333
} from '@fortawesome/free-solid-svg-icons';
34-
import * as I18n from './i18n';
34+
import I18n from './i18n';
3535

3636
const styles = {
3737
body: {

0 commit comments

Comments
 (0)