UNPKG

1.3 kBJavaScriptView Raw
1/* globals requirejs */
2
3import { warn } from '@ember/debug';
4import links from './utils/links';
5
6/**
7 * @private
8 * @hide
9 */
10export function lookupByFactoryType(type, modulePrefix) {
11 return Object.keys(requirejs.entries).filter(key => {
12 return key.indexOf(`${modulePrefix}/${type}/`) === 0;
13 });
14}
15
16/**
17 * Peeks into the requirejs map and registers all locale data (CLDR & Translations) found.
18 *
19 * @private
20 * @hide
21 */
22export default function(service, owner) {
23 const config = owner.resolveRegistration('config:environment');
24 const cldrs = lookupByFactoryType('cldrs', config.modulePrefix);
25 const translations = lookupByFactoryType('translations', config.modulePrefix);
26
27 if (!cldrs.length) {
28 warn(
29 `[ember-intl] project is missing CLDR data\nIf you are asynchronously loading translation,
30 see: ${links.asyncTranslations}.`,
31 false,
32 {
33 id: 'ember-intl-missing-cldr-data'
34 }
35 );
36 }
37
38 cldrs
39 .map(moduleName => owner.resolveRegistration(`cldr:${moduleName.split('/').pop()}`))
40 .forEach(data => data.forEach(service.addLocaleData));
41
42 translations.forEach(moduleName => {
43 const localeName = moduleName.split('/').pop();
44
45 service.addTranslations(localeName, owner.resolveRegistration(`translation:${localeName}`));
46 });
47}