Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions packages/mdctl-core/streams/section.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const _ = require('lodash'),
},
NON_WRITABLE_KEYS = ['facet'],
SectionsCreated = [],
{ privatesAccessor } = require('@medable/mdctl-core-utils/privates')
{ privatesAccessor } = require('@medable/mdctl-core-utils/privates'),
hash = require('crypto').createHash('md5')

class ExportSection {

Expand Down Expand Up @@ -282,8 +283,23 @@ class ExportSection {
objectPath.push(i)
objectPath.push('data')
if (cnt.data) {
let localeInName;
if (_.isArray(l.locale)){
if(l.locale.length > 1) {
localeInName = hash.update(l.locale.join()).digest('hex')
} else {
if (_.isEqual(l.locale, ['*'])) {
localeInName = 'anyLocale'
} else {
localeInName = l.locale[0]
}
}
} else {
localeInName = l.locale
}

privatesAccessor(this).templateFiles.push({
name: `${name}.${l.locale}.${cnt.name}`,
name: `${name}.${localeInName}.${cnt.name}`,
ext: TEMPLATES_EXT[content.type][cnt.name],
data: cnt.data,
remoteLocation: false,
Expand Down
96 changes: 96 additions & 0 deletions packages/mdctl-core/test/section_template_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
let {ExportSection} = require('../streams/section')
let { assert } = require('chai')

describe('Section templates export', () => {
it('should export template file with locale name if locale is array length 1', () => {
let section = new ExportSection({
type: 'email',
name: 'html',
object: 'template',
localizations: [
{
locale: ['en_US'],
content: [
{
"data": "Content in en_US language",
"name": "html"
}
]
}
]
}, 'template')

section.extractTemplates()
assert(section.templateFiles.length === 1)
assert(section.templateFiles[0].name === 'template.email.html.en_US.html')
})

it('should export template file with name if locale is string', () => {
let section = new ExportSection({
type: 'email',
name: 'html',
object: 'template',
localizations: [
{
locale: 'en_US',
content: [
{
"data": "Content in en_US language",
"name": "html"
}
]
}
]
}, 'template')

section.extractTemplates()
assert(section.templateFiles.length === 1)
assert(section.templateFiles[0].name === 'template.email.html.en_US.html')
})

it('should export template file with name hashed if locale is an array with multiple locales', () => {
let section = new ExportSection({
type: 'email',
name: 'html',
object: 'template',
localizations: [
{
locale: ['en_US', 'en_UK'],
content: [
{
"data": "Content in multiple languages",
"name": "html"
}
]
}
]
}, 'template')

section.extractTemplates()
assert(section.templateFiles.length === 1)
assert(section.templateFiles[0].name === 'template.email.html.a60ac79e553bf2d10265482effc688c2.html')
})

it('should export template file with name anyLocale if locale is ["*"]', () => {
let section = new ExportSection({
type: 'email',
name: 'html',
object: 'template',
localizations: [
{
locale: ['*'],
content: [
{
"data": "Content in multiple languages",
"name": "html"
}
]
}
]
}, 'template')

section.extractTemplates()
assert(section.templateFiles.length === 1)
assert(section.templateFiles[0].name === 'template.email.html.anyLocale.html')
})
})