-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstrip-translations.js
59 lines (55 loc) · 1.85 KB
/
strip-translations.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
const get = require('lodash').get
const processXml = (root, keysToProcess) => {
return Object.keys(keysToProcess).reduce((filterIt, key) => {
if (!root[key]) return true
root[key] = root[key].filter(x => {
const labelKeys = Array.isArray(keysToProcess[key]) ? keysToProcess[key] : [keysToProcess[key]]
return !labelKeys.reduce((filterIt, labelKey) => {
if (typeof (labelKey) === 'object') return processXml(x, labelKey) && filterIt
const labelKeyIsNotTranslated = !x[labelKey] || !x[labelKey][0]
if (labelKeyIsNotTranslated) delete x[labelKey]
return filterIt && labelKeyIsNotTranslated
}, true)
})
return filterIt && !root[key].length
}, true)
}
module.exports = async (context, helpers) => {
if (get(context, 'config.objectTranslations.stripUntranslatedFields')) {
helpers.xmlTransformer('translations/**/*', async (filename, fJson) => {
processXml(fJson, {
reportTypes: [
'label',
'description',
{ sections: 'label' }
],
customApplications: 'label',
customLabels: 'label',
customTabs: 'label'
})
})
helpers.xmlTransformer('standardValueSetTranslations/**/*', async (filename, fJson) => {
processXml(fJson, { valueTranslation: 'translation' })
})
helpers.xmlTransformer('objectTranslations/**/*', async (filename, fJson) => {
processXml(fJson, {
validationRules: 'errorMessage',
webLinks: 'label',
recordTypes: [
'label',
'description'
],
quickActions: 'label',
fields: [
'help',
'label',
'relationshipLabel',
{ picklistValues: 'translation' },
{ lookupFilter: 'errorMessage' }
],
layouts: { sections: 'label' },
sharingReasons: 'label'
})
})
}
}