-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextract-lang.js
More file actions
33 lines (29 loc) · 821 Bytes
/
extract-lang.js
File metadata and controls
33 lines (29 loc) · 821 Bytes
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
!function(exports) {
exports.extractLang = extractLang
function extractLang(translations, lang) {
var missing = []
, out = extract(translations, "")
if (missing[0]) {
console.error("WARNING! Missing '%s' translations: %s [%s]", lang, missing.length, missing+"")
}
return out
function extract(map, path) {
var key
, out = {}
, translations = map.translations
if (!translations) return map[lang]
for (key in translations) {
out[key] = extract(translations[key], path + key + ".")
if (
out[key] === key ||
out[key] === void 0 && missing.push(path + key) ||
isObject(out[key]) && Object.keys(out[key]).length < 1
) delete out[key]
}
return out
}
function isObject(obj) {
return obj && obj.constructor === Object
}
}
}(this) // jshint ignore:line