summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src/actions/i18n.js
blob: 115c5a15e818988f7494cfbfab65b6c9363c60a1 (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
28
29
30
31
32
33
const ACTION_TYPES = require('./TYPES');

/**
 * Register messages for a locale
 * @param {String} locale
 * @param {Map<String:String>} messages
 * @return {Action}
 */
function registerLocale(locale, messages) {
    return { type: ACTION_TYPES.I18N_REGISTER_LOCALE, locale, messages };
}

/**
 * Register multiple locales
 * @param {Map<String:Object>} locales
 * @return {Action}
 */
function registerLocales(locales) {
    return (dispatch) => {
        for (const locale in locales) {
            if (!locales.hasOwnProperty(locale)) {
                continue;
            }

            dispatch(registerLocale(locale, locales[locale]));
        }
    };
}

module.exports = {
    registerLocale,
    registerLocales
};