summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src/reducers/i18n.js
blob: 4ffd129c8c6e8f2f9c9ce9cb8e1e84774ce2fb63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const { Record, Map } = require('immutable');
const ACTION_TYPES = require('../actions/TYPES');

const I18nState = Record({
    locale: 'en',
    // Map of locale -> Map<String:String>
    messages: Map()
});

function reduceI18n(state, action) {
    state = state || I18nState();
    switch (action.type) {

    case ACTION_TYPES.I18N_REGISTER_LOCALE:
        return state.merge({
            messages: state.messages.set(action.locale,
                state.messages.get(action.locale, Map()).merge(action.messages)
            )
        });

    default:
        return state;

    }
}

module.exports = reduceI18n;