1 |
|
2 |
|
3 | import { warn } from '@ember/debug';
|
4 | import links from './utils/links';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export function lookupByFactoryType(type, modulePrefix) {
|
11 | return Object.keys(requirejs.entries).filter(key => {
|
12 | return key.indexOf(`${modulePrefix}/${type}/`) === 0;
|
13 | });
|
14 | }
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | export 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 | }
|