-
Notifications
You must be signed in to change notification settings - Fork 2
/
locale.js
70 lines (54 loc) · 1.5 KB
/
locale.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import Ember from 'ember';
import locales from './locales';
var get = Ember.get;
var keys = Ember.keys;
var typeOf = Ember.typeOf;
export function optionsFor(options) {
if (typeOf(options) === 'string') {
options = {
base: options
};
}
Ember.assert('You have to specify a default locale for the application.', options && options.base);
if (!options.locales) {
options.locales = locales;
}
locales.toArray = function() {
var keys = [];
for (var prop in this) {
if (hasOwnProperty.call(this, prop) && prop !== 'toArray') {
keys.push(prop);
}
}
var items = keys.map(function(item) {
return this[item];
}, this);
return Ember.A(items);
};
return options;
}
export function setup(container, locale, formats) {
var locales = get(locale, 'locales');
var _keys = keys(locales);
var _key, _locale, _cldr, _data;
for (var i = 0, len = _keys.length; i < len; i++) {
_key = _keys[i];
_locale = locales[_key];
_cldr = container.resolve('locale:' + _key + '-cldr');
_data = container.resolve('locale:' + _key);
if (!_cldr || !_data) {
_locale.enabled = false;
_locale.cldr = null;
_locale.messages = null;
_locale.formats = null;
continue;
}
formats.message.__addLocaleData(_cldr);
formats.relative.__addLocaleData(_cldr);
_locale.enabled = true;
_locale.cldr = _cldr;
_locale.messages = _data.messages;
_locale.formats = _data.formats;
}
}
export default locales;