UNPKG

847 BJavaScriptView Raw
1import { get } from '@ember/object';
2import makeIntlHelper from './-private/make-intl-helper';
3import pickLastLocale from './-private/pick-last-locale';
4
5/**
6 * Invokes the `addTranslations` method of the `intl` service. The first
7 * parameter, the `localeName`, is optional and will default to the last
8 * currently enabled locale. This means, that if you invoke this helper with
9 * just translations, they will be added to the last locale and all other
10 * locales will be tried before.
11 *
12 * @function addTranslations
13 * @param {string} [localeName]
14 * @param {object} translations
15 */
16export default makeIntlHelper((intl, localeName, translations) => {
17 if (typeof localeName === 'object') {
18 translations = localeName;
19 localeName = pickLastLocale(get(intl, 'locale'));
20 }
21
22 return intl.addTranslations(localeName, translations);
23});