locize-cli 10.3.2 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +8 -0
- package/add.js +46 -51
- package/bin/locize +852 -493
- package/combineSubkeyPreprocessor.js +86 -85
- package/convertToDesiredFormat.js +125 -125
- package/convertToFlatFormat.js +154 -154
- package/copyVersion.js +37 -37
- package/createBranch.js +33 -33
- package/deleteBranch.js +52 -52
- package/deleteNamespace.js +20 -20
- package/download.js +286 -284
- package/filterNamespaces.js +5 -5
- package/format.js +101 -101
- package/formats.js +10 -10
- package/get.js +40 -37
- package/getBranches.js +22 -22
- package/getJob.js +22 -22
- package/getProjectStats.js +22 -22
- package/getRemoteLanguages.js +19 -19
- package/getRemoteNamespace.js +60 -56
- package/index.js +1 -1
- package/isValidUuid.js +2 -2
- package/mergeBranch.js +55 -55
- package/migrate.js +147 -149
- package/missing.js +90 -90
- package/package.json +4 -2
- package/parseLocalLanguage.js +110 -110
- package/parseLocalLanguages.js +14 -14
- package/parseLocalReference.js +6 -6
- package/publishVersion.js +34 -34
- package/removeUndefinedFromArrays.js +8 -8
- package/removeVersion.js +34 -34
- package/request.js +32 -32
- package/shouldUnflatten.js +11 -11
- package/sortFlatResources.js +7 -7
- package/sync.js +425 -421
- package/unflatten.js +40 -40
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
const yaml = require('yaml')
|
|
1
|
+
const yaml = require('yaml')
|
|
2
2
|
|
|
3
3
|
const delimiter = {
|
|
4
4
|
i18next: '_',
|
|
5
5
|
i18njs: '.'
|
|
6
|
-
}
|
|
6
|
+
}
|
|
7
7
|
|
|
8
8
|
const detectFormat = (keys) => {
|
|
9
|
-
const i18nextMatches = keys.filter((k) => k.indexOf(delimiter.i18next) > 0).length
|
|
10
|
-
const i18njsMatches = keys.filter((k) => k.indexOf(delimiter.i18njs) > 0).length
|
|
9
|
+
const i18nextMatches = keys.filter((k) => k.indexOf(delimiter.i18next) > 0).length
|
|
10
|
+
const i18njsMatches = keys.filter((k) => k.indexOf(delimiter.i18njs) > 0).length
|
|
11
11
|
if (i18nextMatches > i18njsMatches) {
|
|
12
|
-
return 'i18next'
|
|
12
|
+
return 'i18next'
|
|
13
13
|
}
|
|
14
14
|
if (i18nextMatches < i18njsMatches) {
|
|
15
|
-
return 'i18njs'
|
|
15
|
+
return 'i18njs'
|
|
16
16
|
}
|
|
17
|
-
}
|
|
17
|
+
}
|
|
18
18
|
|
|
19
19
|
const getBaseKey = (delimiter) => (k) => {
|
|
20
|
-
const parts = k.split(delimiter)
|
|
21
|
-
parts.pop()
|
|
22
|
-
const baseKey = parts.join(delimiter)
|
|
23
|
-
return baseKey
|
|
24
|
-
}
|
|
20
|
+
const parts = k.split(delimiter)
|
|
21
|
+
parts.pop()
|
|
22
|
+
const baseKey = parts.join(delimiter)
|
|
23
|
+
return baseKey
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
const uniq = (value, index, self) => self.indexOf(value) === index
|
|
26
|
+
const uniq = (value, index, self) => self.indexOf(value) === index
|
|
27
27
|
|
|
28
28
|
const stringify = (o) => {
|
|
29
|
-
let str = yaml.stringify(o)
|
|
30
|
-
const subKeys = Object.keys(o)
|
|
29
|
+
let str = yaml.stringify(o)
|
|
30
|
+
const subKeys = Object.keys(o)
|
|
31
31
|
subKeys.forEach((sk) => {
|
|
32
32
|
if (isNaN(sk)) {
|
|
33
|
-
str = str.replace(new RegExp(`^(?:${sk}: )+`, 'm'), `{${sk}}: `)
|
|
33
|
+
str = str.replace(new RegExp(`^(?:${sk}: )+`, 'm'), `{${sk}}: `)
|
|
34
34
|
} else {
|
|
35
|
-
str = str.replace(new RegExp(`^(?:'${sk}': )+`, 'm'), `{${sk}}: `)
|
|
35
|
+
str = str.replace(new RegExp(`^(?:'${sk}': )+`, 'm'), `{${sk}}: `)
|
|
36
36
|
}
|
|
37
|
-
})
|
|
38
|
-
return str
|
|
39
|
-
}
|
|
37
|
+
})
|
|
38
|
+
return str
|
|
39
|
+
}
|
|
40
40
|
|
|
41
41
|
const transformKeys = (segments, baseKeys, toMerge, deli) => {
|
|
42
42
|
baseKeys.forEach((bk) => {
|
|
43
43
|
const asObj = toMerge[bk].reduce((mem, k) => {
|
|
44
|
-
const subKey = k.substring((bk + deli).length)
|
|
44
|
+
const subKey = k.substring((bk + deli).length)
|
|
45
45
|
// special handling for i18next v3
|
|
46
46
|
if (deli === delimiter.i18next && subKey === 'plural' && segments[bk]) {
|
|
47
|
-
mem['__'] = segments[bk]
|
|
48
|
-
delete segments[bk]
|
|
47
|
+
mem['__'] = segments[bk]
|
|
48
|
+
delete segments[bk]
|
|
49
49
|
}
|
|
50
|
-
mem[subKey] = segments[k]
|
|
51
|
-
return mem
|
|
52
|
-
}, {})
|
|
50
|
+
mem[subKey] = segments[k]
|
|
51
|
+
return mem
|
|
52
|
+
}, {})
|
|
53
53
|
if (Object.keys(asObj).length > 0) {
|
|
54
|
-
const value = stringify(asObj)
|
|
55
|
-
segments[`${bk}__#locize.com/combinedSubkey`] = value
|
|
54
|
+
const value = stringify(asObj)
|
|
55
|
+
segments[`${bk}__#locize.com/combinedSubkey`] = value
|
|
56
56
|
toMerge[bk].forEach((k) => {
|
|
57
|
-
delete segments[k]
|
|
58
|
-
})
|
|
57
|
+
delete segments[k]
|
|
58
|
+
})
|
|
59
59
|
}
|
|
60
|
-
})
|
|
61
|
-
return segments
|
|
62
|
-
}
|
|
60
|
+
})
|
|
61
|
+
return segments
|
|
62
|
+
}
|
|
63
63
|
|
|
64
64
|
// CLDR
|
|
65
65
|
const pluralForms = [
|
|
@@ -69,86 +69,87 @@ const pluralForms = [
|
|
|
69
69
|
'few',
|
|
70
70
|
'many',
|
|
71
71
|
'other'
|
|
72
|
-
]
|
|
72
|
+
]
|
|
73
73
|
|
|
74
|
-
const endsWithPluralForm = (k) => !!pluralForms.find((f) => k.endsWith(`.${f}`)) || !!pluralForms.find((f) => k.endsWith(`_${f}`)) || /_\d+$/.test(k) || k.endsWith('_plural')
|
|
74
|
+
const endsWithPluralForm = (k) => !!pluralForms.find((f) => k.endsWith(`.${f}`)) || !!pluralForms.find((f) => k.endsWith(`_${f}`)) || /_\d+$/.test(k) || k.endsWith('_plural')
|
|
75
75
|
|
|
76
76
|
const prepareExport = (refRes, trgRes) => {
|
|
77
|
-
const refLngKeys = Object.keys(refRes)
|
|
78
|
-
const trgLngKeys = Object.keys(trgRes)
|
|
77
|
+
const refLngKeys = Object.keys(refRes)
|
|
78
|
+
const trgLngKeys = Object.keys(trgRes)
|
|
79
79
|
|
|
80
|
-
const nonMatchInRef = refLngKeys.filter((k) => trgLngKeys.indexOf(k) < 0 && endsWithPluralForm(k))
|
|
81
|
-
const nonMatchInTrg = trgLngKeys.filter((k) => refLngKeys.indexOf(k) < 0 && endsWithPluralForm(k))
|
|
80
|
+
const nonMatchInRef = refLngKeys.filter((k) => trgLngKeys.indexOf(k) < 0 && endsWithPluralForm(k))
|
|
81
|
+
const nonMatchInTrg = trgLngKeys.filter((k) => refLngKeys.indexOf(k) < 0 && endsWithPluralForm(k))
|
|
82
82
|
|
|
83
|
-
const allMatches = nonMatchInRef.concat(nonMatchInTrg)
|
|
83
|
+
const allMatches = nonMatchInRef.concat(nonMatchInTrg)
|
|
84
84
|
|
|
85
|
-
const format = detectFormat(allMatches)
|
|
86
|
-
if (!format) return { ref: refRes, trg: trgRes }
|
|
85
|
+
const format = detectFormat(allMatches)
|
|
86
|
+
if (!format) return { ref: refRes, trg: trgRes }
|
|
87
87
|
|
|
88
|
-
const nonMatchBaseKeysInRef = nonMatchInRef.map(getBaseKey(delimiter[format])).filter(uniq)
|
|
89
|
-
const nonMatchBaseKeysInTrg = nonMatchInTrg.map(getBaseKey(delimiter[format])).filter(uniq)
|
|
90
|
-
const nonMatchBaseKeys = nonMatchBaseKeysInRef.concat(nonMatchBaseKeysInTrg).filter(uniq)
|
|
88
|
+
const nonMatchBaseKeysInRef = nonMatchInRef.map(getBaseKey(delimiter[format])).filter(uniq)
|
|
89
|
+
const nonMatchBaseKeysInTrg = nonMatchInTrg.map(getBaseKey(delimiter[format])).filter(uniq)
|
|
90
|
+
const nonMatchBaseKeys = nonMatchBaseKeysInRef.concat(nonMatchBaseKeysInTrg).filter(uniq)
|
|
91
91
|
|
|
92
92
|
const toMergeInRef = nonMatchBaseKeys.reduce((mem, bk) => {
|
|
93
|
-
mem[bk] = refLngKeys.filter((k) => k.indexOf(bk + delimiter[format]) === 0)
|
|
94
|
-
return mem
|
|
95
|
-
}, {})
|
|
93
|
+
mem[bk] = refLngKeys.filter((k) => k.indexOf(bk + delimiter[format]) === 0)
|
|
94
|
+
return mem
|
|
95
|
+
}, {})
|
|
96
96
|
const toMergeInTrg = nonMatchBaseKeys.reduce((mem, bk) => {
|
|
97
|
-
mem[bk] = trgLngKeys.filter((k) => k.indexOf(bk + delimiter[format]) === 0)
|
|
98
|
-
return mem
|
|
99
|
-
}, {})
|
|
97
|
+
mem[bk] = trgLngKeys.filter((k) => k.indexOf(bk + delimiter[format]) === 0)
|
|
98
|
+
return mem
|
|
99
|
+
}, {})
|
|
100
100
|
|
|
101
|
-
let falseFlags = nonMatchBaseKeysInRef.filter((k) => toMergeInRef[k].length < 2 && (!toMergeInTrg[k] || toMergeInTrg[k].length < 2))
|
|
102
|
-
falseFlags = falseFlags.concat(nonMatchBaseKeysInTrg.filter((k) => toMergeInTrg[k].length < 2 && (!toMergeInRef[k] || toMergeInRef[k].length < 2)))
|
|
101
|
+
let falseFlags = nonMatchBaseKeysInRef.filter((k) => toMergeInRef[k].length < 2 && (!toMergeInTrg[k] || toMergeInTrg[k].length < 2))
|
|
102
|
+
falseFlags = falseFlags.concat(nonMatchBaseKeysInTrg.filter((k) => toMergeInTrg[k].length < 2 && (!toMergeInRef[k] || toMergeInRef[k].length < 2)))
|
|
103
103
|
falseFlags.forEach((k) => {
|
|
104
|
-
delete toMergeInRef[k]
|
|
105
|
-
delete toMergeInTrg[k]
|
|
106
|
-
nonMatchBaseKeys.splice(nonMatchBaseKeys.indexOf(k), 1)
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
const transformedRef = transformKeys(refRes, nonMatchBaseKeys, toMergeInRef, delimiter[format])
|
|
110
|
-
const transformedTrg = transformKeys(trgRes, nonMatchBaseKeys, toMergeInTrg, delimiter[format])
|
|
111
|
-
return { ref: transformedRef, trg: transformedTrg }
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
104
|
+
delete toMergeInRef[k]
|
|
105
|
+
delete toMergeInTrg[k]
|
|
106
|
+
nonMatchBaseKeys.splice(nonMatchBaseKeys.indexOf(k), 1)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
const transformedRef = transformKeys(refRes, nonMatchBaseKeys, toMergeInRef, delimiter[format])
|
|
110
|
+
const transformedTrg = transformKeys(trgRes, nonMatchBaseKeys, toMergeInTrg, delimiter[format])
|
|
111
|
+
return { ref: transformedRef, trg: transformedTrg }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// eslint-disable-next-line prefer-regex-literals
|
|
115
|
+
const skRegex = new RegExp('^(?:{(.+)})+', 'gm')
|
|
115
116
|
const parse = (s) => {
|
|
116
|
-
let matchArray
|
|
117
|
+
let matchArray
|
|
117
118
|
while ((matchArray = skRegex.exec(s)) !== null) {
|
|
118
|
-
const [match, sk] = matchArray
|
|
119
|
+
const [match, sk] = matchArray
|
|
119
120
|
if (isNaN(sk)) {
|
|
120
|
-
s = s.replace(new RegExp(`^(?:${match}: )+`, 'm'), `${sk}: `)
|
|
121
|
+
s = s.replace(new RegExp(`^(?:${match}: )+`, 'm'), `${sk}: `)
|
|
121
122
|
} else {
|
|
122
|
-
const escapedMatch = match.replace('{', '\\{').replace('}', '\\}')
|
|
123
|
-
s = s.replace(new RegExp(`^(?:${escapedMatch}: )+`, 'm'), `${sk}: `)
|
|
123
|
+
const escapedMatch = match.replace('{', '\\{').replace('}', '\\}')
|
|
124
|
+
s = s.replace(new RegExp(`^(?:${escapedMatch}: )+`, 'm'), `${sk}: `)
|
|
124
125
|
}
|
|
125
126
|
}
|
|
126
|
-
return yaml.parse(s)
|
|
127
|
-
}
|
|
127
|
+
return yaml.parse(s)
|
|
128
|
+
}
|
|
128
129
|
|
|
129
130
|
const prepareImport = (resources) => {
|
|
130
|
-
const keys = Object.keys(resources)
|
|
131
|
+
const keys = Object.keys(resources)
|
|
131
132
|
keys.forEach((k) => {
|
|
132
133
|
if (k.indexOf('__#locize.com/combinedSubkey') > -1) {
|
|
133
|
-
const baseKey = k.substring(0, k.indexOf('__#locize.com/combinedSubkey'))
|
|
134
|
+
const baseKey = k.substring(0, k.indexOf('__#locize.com/combinedSubkey'))
|
|
134
135
|
if (resources[k]) {
|
|
135
|
-
const parsed = parse(resources[k])
|
|
136
|
-
Object.keys(parsed).
|
|
137
|
-
const skVal = parsed[sk]
|
|
138
|
-
resources[`${baseKey}_${sk}`] = skVal
|
|
136
|
+
const parsed = parse(resources[k])
|
|
137
|
+
Object.keys(parsed).forEach((sk) => {
|
|
138
|
+
const skVal = parsed[sk]
|
|
139
|
+
resources[`${baseKey}_${sk}`] = skVal
|
|
139
140
|
if (sk === '__') {
|
|
140
|
-
resources[baseKey] = resources[`${baseKey}_${sk}`]
|
|
141
|
-
delete resources[`${baseKey}_${sk}`]
|
|
141
|
+
resources[baseKey] = resources[`${baseKey}_${sk}`]
|
|
142
|
+
delete resources[`${baseKey}_${sk}`]
|
|
142
143
|
}
|
|
143
|
-
})
|
|
144
|
-
delete resources[k]
|
|
144
|
+
})
|
|
145
|
+
delete resources[k]
|
|
145
146
|
}
|
|
146
147
|
}
|
|
147
|
-
})
|
|
148
|
-
return resources
|
|
149
|
-
}
|
|
148
|
+
})
|
|
149
|
+
return resources
|
|
150
|
+
}
|
|
150
151
|
|
|
151
152
|
module.exports = {
|
|
152
153
|
prepareExport,
|
|
153
154
|
prepareImport
|
|
154
|
-
}
|
|
155
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
const flatten = require('flat')
|
|
2
|
-
const i18next2po = require('gettext-converter/cjs/i18next2po')
|
|
3
|
-
const csvjson = require('csvjson')
|
|
4
|
-
const xlsx = require('xlsx')
|
|
5
|
-
const yaml = require('yaml')
|
|
6
|
-
const js2asr = require('android-string-resource/cjs/js2asr')
|
|
7
|
-
const stringsFile = require('strings-file')
|
|
8
|
-
const createxliff = require('xliff/cjs/createxliff')
|
|
9
|
-
const createxliff12 = require('xliff/cjs/createxliff12')
|
|
10
|
-
const js2resx = require('resx/cjs/js2resx')
|
|
11
|
-
const js2ftl = require('fluent_conv/cjs/js2ftl')
|
|
12
|
-
const js2tmx = require('tmexchange/cjs/js2tmx')
|
|
13
|
-
const js2laravel = require('laravelphp/cjs/js2laravel')
|
|
14
|
-
const javaProperties = require('@js.properties/properties')
|
|
15
|
-
const unflatten = require('./unflatten')
|
|
16
|
-
const getRemoteNamespace = require('./getRemoteNamespace')
|
|
17
|
-
const removeUndefinedFromArrays = require('./removeUndefinedFromArrays')
|
|
18
|
-
const shouldUnflatten = require('./shouldUnflatten')
|
|
19
|
-
const prepareCombinedExport = require('./combineSubkeyPreprocessor').prepareExport
|
|
1
|
+
const flatten = require('flat')
|
|
2
|
+
const i18next2po = require('gettext-converter/cjs/i18next2po')
|
|
3
|
+
const csvjson = require('csvjson')
|
|
4
|
+
const xlsx = require('xlsx')
|
|
5
|
+
const yaml = require('yaml')
|
|
6
|
+
const js2asr = require('android-string-resource/cjs/js2asr')
|
|
7
|
+
const stringsFile = require('strings-file')
|
|
8
|
+
const createxliff = require('xliff/cjs/createxliff')
|
|
9
|
+
const createxliff12 = require('xliff/cjs/createxliff12')
|
|
10
|
+
const js2resx = require('resx/cjs/js2resx')
|
|
11
|
+
const js2ftl = require('fluent_conv/cjs/js2ftl')
|
|
12
|
+
const js2tmx = require('tmexchange/cjs/js2tmx')
|
|
13
|
+
const js2laravel = require('laravelphp/cjs/js2laravel')
|
|
14
|
+
const javaProperties = require('@js.properties/properties')
|
|
15
|
+
const unflatten = require('./unflatten')
|
|
16
|
+
const getRemoteNamespace = require('./getRemoteNamespace')
|
|
17
|
+
const removeUndefinedFromArrays = require('./removeUndefinedFromArrays')
|
|
18
|
+
const shouldUnflatten = require('./shouldUnflatten')
|
|
19
|
+
const prepareCombinedExport = require('./combineSubkeyPreprocessor').prepareExport
|
|
20
20
|
|
|
21
21
|
const convertToDesiredFormat = (
|
|
22
22
|
opt,
|
|
@@ -26,29 +26,29 @@ const convertToDesiredFormat = (
|
|
|
26
26
|
lastModified,
|
|
27
27
|
cb
|
|
28
28
|
) => {
|
|
29
|
-
opt.getNamespace = opt.getNamespace || getRemoteNamespace
|
|
30
|
-
const isEmpty = !data || Object.keys(data).length === 0
|
|
29
|
+
opt.getNamespace = opt.getNamespace || getRemoteNamespace
|
|
30
|
+
const isEmpty = !data || Object.keys(data).length === 0
|
|
31
31
|
try {
|
|
32
32
|
if (opt.format === 'json') {
|
|
33
33
|
try {
|
|
34
|
-
data = unflatten(data, true)
|
|
34
|
+
data = unflatten(data, true)
|
|
35
35
|
} catch (err) {}
|
|
36
|
-
cb(null, JSON.stringify(data, null, 2))
|
|
37
|
-
return
|
|
36
|
+
cb(null, JSON.stringify(data, null, 2))
|
|
37
|
+
return
|
|
38
38
|
}
|
|
39
39
|
if (opt.format === 'nested') {
|
|
40
40
|
try {
|
|
41
|
-
data = unflatten(data)
|
|
41
|
+
data = unflatten(data)
|
|
42
42
|
} catch (err) {}
|
|
43
|
-
cb(null, JSON.stringify(data, null, 2))
|
|
44
|
-
return
|
|
43
|
+
cb(null, JSON.stringify(data, null, 2))
|
|
44
|
+
return
|
|
45
45
|
}
|
|
46
46
|
if (opt.format === 'flat') {
|
|
47
|
-
cb(null, JSON.stringify(flatten(data), null, 2))
|
|
48
|
-
return
|
|
47
|
+
cb(null, JSON.stringify(flatten(data), null, 2))
|
|
48
|
+
return
|
|
49
49
|
}
|
|
50
50
|
if (opt.format === 'po' || opt.format === 'gettext') {
|
|
51
|
-
const flatData = flatten(data)
|
|
51
|
+
const flatData = flatten(data)
|
|
52
52
|
|
|
53
53
|
const gettextOpt = {
|
|
54
54
|
project: 'locize',
|
|
@@ -57,138 +57,138 @@ const convertToDesiredFormat = (
|
|
|
57
57
|
poRevisionDate: lastModified,
|
|
58
58
|
ctxSeparator: '_ is default but we set it to something that is never found!!!',
|
|
59
59
|
persistMsgIdPlural: true
|
|
60
|
-
}
|
|
61
|
-
cb(null, i18next2po(lng, flatData, gettextOpt))
|
|
62
|
-
return
|
|
60
|
+
}
|
|
61
|
+
cb(null, i18next2po(lng, flatData, gettextOpt))
|
|
62
|
+
return
|
|
63
63
|
}
|
|
64
64
|
if (opt.format === 'po_i18next' || opt.format === 'gettext_i18next') {
|
|
65
|
-
const flatData = flatten(data)
|
|
66
|
-
const compatibilityJSON = !!Object.keys(flatData).find((k) => /_(zero|one|two|few|many|other)/.test(k)) && 'v4'
|
|
65
|
+
const flatData = flatten(data)
|
|
66
|
+
const compatibilityJSON = !!Object.keys(flatData).find((k) => /_(zero|one|two|few|many|other)/.test(k)) && 'v4'
|
|
67
67
|
const gettextOpt = {
|
|
68
68
|
project: 'locize',
|
|
69
69
|
language: lng,
|
|
70
70
|
potCreationDate: lastModified,
|
|
71
71
|
poRevisionDate: lastModified,
|
|
72
72
|
compatibilityJSON
|
|
73
|
-
}
|
|
74
|
-
cb(null, i18next2po(lng, flatData, gettextOpt))
|
|
75
|
-
return
|
|
73
|
+
}
|
|
74
|
+
cb(null, i18next2po(lng, flatData, gettextOpt))
|
|
75
|
+
return
|
|
76
76
|
}
|
|
77
77
|
if (opt.format === 'csv') {
|
|
78
78
|
opt.getNamespace(opt, opt.referenceLanguage, namespace, (err, refNs) => {
|
|
79
|
-
if (err) return cb(err)
|
|
79
|
+
if (err) return cb(err)
|
|
80
80
|
|
|
81
81
|
const js2CsvData = Object.keys(flatten(data)).reduce((mem, k) => {
|
|
82
|
-
const value = data[k] || ''
|
|
82
|
+
const value = data[k] || ''
|
|
83
83
|
const line = {
|
|
84
84
|
// https://en.wikipedia.org/wiki/Delimiter-separated_values
|
|
85
85
|
key: k.replace(/"/g, '""'),
|
|
86
86
|
[opt.referenceLanguage]: refNs[k] || '',
|
|
87
87
|
[lng]: value.replace(/"/g, '""')
|
|
88
|
-
}
|
|
89
|
-
line.key = line.key.replace(/\n/g, '\\NeWlInE\\')
|
|
88
|
+
}
|
|
89
|
+
line.key = line.key.replace(/\n/g, '\\NeWlInE\\')
|
|
90
90
|
line[opt.referenceLanguage] = line[opt.referenceLanguage].replace(
|
|
91
91
|
/\n/g,
|
|
92
92
|
'\\NeWlInE\\'
|
|
93
|
-
)
|
|
94
|
-
line[lng] = line[lng].replace(/\n/g, '\\NeWlInE\\')
|
|
95
|
-
mem.push(line)
|
|
93
|
+
)
|
|
94
|
+
line[lng] = line[lng].replace(/\n/g, '\\NeWlInE\\')
|
|
95
|
+
mem.push(line)
|
|
96
96
|
|
|
97
|
-
return mem
|
|
98
|
-
}, [])
|
|
97
|
+
return mem
|
|
98
|
+
}, [])
|
|
99
99
|
const options = {
|
|
100
100
|
delimiter: ',',
|
|
101
101
|
wrap: true,
|
|
102
102
|
headers: 'relative'
|
|
103
103
|
// objectDenote: '.',
|
|
104
104
|
// arrayDenote: '[]'
|
|
105
|
-
}
|
|
105
|
+
}
|
|
106
106
|
cb(
|
|
107
107
|
null,
|
|
108
108
|
`\ufeff${csvjson
|
|
109
109
|
.toCSV(js2CsvData, options)
|
|
110
110
|
.replace(/\\NeWlInE\\/g, '\n')}`
|
|
111
|
-
)
|
|
112
|
-
})
|
|
113
|
-
return
|
|
111
|
+
)
|
|
112
|
+
})
|
|
113
|
+
return
|
|
114
114
|
}
|
|
115
115
|
if (opt.format === 'xlsx') {
|
|
116
116
|
opt.getNamespace(opt, opt.referenceLanguage, namespace, (err, refNs) => {
|
|
117
|
-
if (err) return cb(err)
|
|
117
|
+
if (err) return cb(err)
|
|
118
118
|
|
|
119
119
|
const js2XlsxData = Object.keys(flatten(data)).reduce((mem, k) => {
|
|
120
|
-
const value = data[k] || ''
|
|
120
|
+
const value = data[k] || ''
|
|
121
121
|
const line = {
|
|
122
122
|
key: k,
|
|
123
123
|
[opt.referenceLanguage]: refNs[k] || '',
|
|
124
124
|
[lng]: value
|
|
125
|
-
}
|
|
126
|
-
mem.push(line)
|
|
125
|
+
}
|
|
126
|
+
mem.push(line)
|
|
127
127
|
|
|
128
|
-
return mem
|
|
129
|
-
}, [])
|
|
128
|
+
return mem
|
|
129
|
+
}, [])
|
|
130
130
|
|
|
131
|
-
const worksheet = xlsx.utils.json_to_sheet(js2XlsxData)
|
|
132
|
-
const workbook = xlsx.utils.book_new()
|
|
133
|
-
let workSheetName = namespace
|
|
134
|
-
if (workSheetName.length > 31) workSheetName = workSheetName.substring(0, 31)
|
|
135
|
-
workbook.SheetNames.push(workSheetName)
|
|
136
|
-
workbook.Sheets[workSheetName] = worksheet
|
|
131
|
+
const worksheet = xlsx.utils.json_to_sheet(js2XlsxData)
|
|
132
|
+
const workbook = xlsx.utils.book_new()
|
|
133
|
+
let workSheetName = namespace
|
|
134
|
+
if (workSheetName.length > 31) workSheetName = workSheetName.substring(0, 31)
|
|
135
|
+
workbook.SheetNames.push(workSheetName)
|
|
136
|
+
workbook.Sheets[workSheetName] = worksheet
|
|
137
137
|
|
|
138
|
-
const wbout = xlsx.write(workbook, { type: 'buffer' })
|
|
138
|
+
const wbout = xlsx.write(workbook, { type: 'buffer' })
|
|
139
139
|
|
|
140
|
-
cb(null, wbout)
|
|
141
|
-
})
|
|
142
|
-
return
|
|
140
|
+
cb(null, wbout)
|
|
141
|
+
})
|
|
142
|
+
return
|
|
143
143
|
}
|
|
144
144
|
if (
|
|
145
145
|
opt.format === 'yaml' ||
|
|
146
146
|
opt.format === 'yml'
|
|
147
147
|
) {
|
|
148
|
-
if (isEmpty) return cb(null, '')
|
|
149
|
-
cb(null, yaml.stringify(flatten(data)))
|
|
150
|
-
return
|
|
148
|
+
if (isEmpty) return cb(null, '')
|
|
149
|
+
cb(null, yaml.stringify(flatten(data)))
|
|
150
|
+
return
|
|
151
151
|
}
|
|
152
152
|
if (
|
|
153
153
|
opt.format === 'yaml-nested' ||
|
|
154
154
|
opt.format === 'yml-nested'
|
|
155
155
|
) {
|
|
156
|
-
if (isEmpty) return cb(null, '')
|
|
157
|
-
cb(null, yaml.stringify(shouldUnflatten(data) ? unflatten(data) : data))
|
|
158
|
-
return
|
|
156
|
+
if (isEmpty) return cb(null, '')
|
|
157
|
+
cb(null, yaml.stringify(shouldUnflatten(data) ? unflatten(data) : data))
|
|
158
|
+
return
|
|
159
159
|
}
|
|
160
160
|
if (
|
|
161
161
|
opt.format === 'yaml-rails' ||
|
|
162
162
|
opt.format === 'yml-rails'
|
|
163
163
|
) {
|
|
164
|
-
if (isEmpty) return cb(null, '')
|
|
165
|
-
|
|
166
|
-
newData[lng] = shouldUnflatten(data) ? unflatten(data) : data
|
|
167
|
-
cb(null, yaml.stringify(removeUndefinedFromArrays(newData)))
|
|
168
|
-
return
|
|
164
|
+
if (isEmpty) return cb(null, '')
|
|
165
|
+
const newData = {}
|
|
166
|
+
newData[lng] = shouldUnflatten(data) ? unflatten(data) : data
|
|
167
|
+
cb(null, yaml.stringify(removeUndefinedFromArrays(newData)))
|
|
168
|
+
return
|
|
169
169
|
}
|
|
170
170
|
if (
|
|
171
171
|
opt.format === 'yaml-rails-ns' ||
|
|
172
172
|
opt.format === 'yml-rails-ns'
|
|
173
173
|
) {
|
|
174
|
-
if (isEmpty) return cb(null, '')
|
|
175
|
-
|
|
176
|
-
newDataNs[lng] = {}
|
|
177
|
-
newDataNs[lng][namespace] = shouldUnflatten(data) ? unflatten(data) : data
|
|
178
|
-
cb(null, yaml.stringify(removeUndefinedFromArrays(newDataNs)))
|
|
179
|
-
return
|
|
174
|
+
if (isEmpty) return cb(null, '')
|
|
175
|
+
const newDataNs = {}
|
|
176
|
+
newDataNs[lng] = {}
|
|
177
|
+
newDataNs[lng][namespace] = shouldUnflatten(data) ? unflatten(data) : data
|
|
178
|
+
cb(null, yaml.stringify(removeUndefinedFromArrays(newDataNs)))
|
|
179
|
+
return
|
|
180
180
|
}
|
|
181
181
|
if (opt.format === 'android') {
|
|
182
|
-
js2asr(flatten(data), cb)
|
|
183
|
-
return
|
|
182
|
+
js2asr(flatten(data), cb)
|
|
183
|
+
return
|
|
184
184
|
}
|
|
185
185
|
if (opt.format === 'strings') {
|
|
186
186
|
Object.keys(data).forEach((k) => {
|
|
187
|
-
if (data[k] === null) delete data[k]
|
|
188
|
-
})
|
|
189
|
-
data = stringsFile.compile(data)
|
|
190
|
-
cb(null, data)
|
|
191
|
-
return
|
|
187
|
+
if (data[k] === null) delete data[k]
|
|
188
|
+
})
|
|
189
|
+
data = stringsFile.compile(data)
|
|
190
|
+
cb(null, data)
|
|
191
|
+
return
|
|
192
192
|
}
|
|
193
193
|
if (
|
|
194
194
|
opt.format === 'xliff2' ||
|
|
@@ -199,46 +199,46 @@ const convertToDesiredFormat = (
|
|
|
199
199
|
const fn =
|
|
200
200
|
opt.format === 'xliff12' || opt.format === 'xlf12'
|
|
201
201
|
? createxliff12
|
|
202
|
-
: createxliff
|
|
202
|
+
: createxliff
|
|
203
203
|
opt.getNamespace(opt, opt.referenceLanguage, namespace, (err, refNs) => {
|
|
204
|
-
if (err) return cb(err)
|
|
204
|
+
if (err) return cb(err)
|
|
205
205
|
|
|
206
|
-
const prepared = prepareCombinedExport(refNs, flatten(data))
|
|
207
|
-
fn(opt.referenceLanguage, lng, prepared.ref, prepared.trg, namespace, cb)
|
|
208
|
-
})
|
|
209
|
-
return
|
|
206
|
+
const prepared = prepareCombinedExport(refNs, flatten(data))
|
|
207
|
+
fn(opt.referenceLanguage, lng, prepared.ref, prepared.trg, namespace, cb)
|
|
208
|
+
})
|
|
209
|
+
return
|
|
210
210
|
}
|
|
211
211
|
if (opt.format === 'resx') {
|
|
212
|
-
js2resx(flatten(data), cb)
|
|
213
|
-
return
|
|
212
|
+
js2resx(flatten(data), cb)
|
|
213
|
+
return
|
|
214
214
|
}
|
|
215
215
|
if (opt.format === 'fluent') {
|
|
216
216
|
Object.keys(data).forEach((k) => {
|
|
217
|
-
if (!data[k] || data[k] === '') delete data[k]
|
|
217
|
+
if (!data[k] || data[k] === '') delete data[k]
|
|
218
218
|
data[k] = data[k].replace(
|
|
219
219
|
new RegExp(String.fromCharCode(160), 'g'),
|
|
220
220
|
String.fromCharCode(32)
|
|
221
|
-
)
|
|
222
|
-
})
|
|
223
|
-
js2ftl(unflatten(data), cb)
|
|
224
|
-
return
|
|
221
|
+
)
|
|
222
|
+
})
|
|
223
|
+
js2ftl(unflatten(data), cb)
|
|
224
|
+
return
|
|
225
225
|
}
|
|
226
226
|
if (opt.format === 'tmx') {
|
|
227
227
|
opt.getNamespace(opt, opt.referenceLanguage, namespace, (err, refNs) => {
|
|
228
|
-
if (err) return cb(err)
|
|
228
|
+
if (err) return cb(err)
|
|
229
229
|
|
|
230
|
-
const js = flatten(data)
|
|
230
|
+
const js = flatten(data)
|
|
231
231
|
const js2TmxData = Object.keys(js).reduce(
|
|
232
232
|
(mem, k) => {
|
|
233
|
-
const refItem = refNs[k]
|
|
234
|
-
if (!refItem) return mem
|
|
233
|
+
const refItem = refNs[k]
|
|
234
|
+
if (!refItem) return mem
|
|
235
235
|
|
|
236
|
-
const value = js[k] || ''
|
|
237
|
-
mem.resources[namespace][k] = {}
|
|
238
|
-
mem.resources[namespace][k][opt.referenceLanguage] = refItem
|
|
239
|
-
mem.resources[namespace][k][lng] = value
|
|
236
|
+
const value = js[k] || ''
|
|
237
|
+
mem.resources[namespace][k] = {}
|
|
238
|
+
mem.resources[namespace][k][opt.referenceLanguage] = refItem
|
|
239
|
+
mem.resources[namespace][k][lng] = value
|
|
240
240
|
|
|
241
|
-
return mem
|
|
241
|
+
return mem
|
|
242
242
|
},
|
|
243
243
|
{
|
|
244
244
|
resources: {
|
|
@@ -246,23 +246,23 @@ const convertToDesiredFormat = (
|
|
|
246
246
|
},
|
|
247
247
|
sourceLanguage: opt.referenceLanguage
|
|
248
248
|
}
|
|
249
|
-
)
|
|
250
|
-
js2tmx(js2TmxData, cb)
|
|
251
|
-
})
|
|
252
|
-
return
|
|
249
|
+
)
|
|
250
|
+
js2tmx(js2TmxData, cb)
|
|
251
|
+
})
|
|
252
|
+
return
|
|
253
253
|
}
|
|
254
254
|
if (opt.format === 'laravel') {
|
|
255
|
-
js2laravel(unflatten(data), cb)
|
|
256
|
-
return
|
|
255
|
+
js2laravel(unflatten(data), cb)
|
|
256
|
+
return
|
|
257
257
|
}
|
|
258
258
|
if (opt.format === 'properties') {
|
|
259
|
-
cb(null, javaProperties.stringifyFromProperties(data, { eol: '\n' }))
|
|
260
|
-
return
|
|
259
|
+
cb(null, javaProperties.stringifyFromProperties(data, { eol: '\n' }))
|
|
260
|
+
return
|
|
261
261
|
}
|
|
262
|
-
cb(new Error(`${opt.format} is not a valid format!`))
|
|
262
|
+
cb(new Error(`${opt.format} is not a valid format!`))
|
|
263
263
|
} catch (err) {
|
|
264
|
-
cb(err)
|
|
264
|
+
cb(err)
|
|
265
265
|
}
|
|
266
|
-
}
|
|
266
|
+
}
|
|
267
267
|
|
|
268
|
-
module.exports = convertToDesiredFormat
|
|
268
|
+
module.exports = convertToDesiredFormat
|