Skip to content

Commit 6582abf

Browse files
Merge pull request #410 from Medable/feature/CTXAPI-1831_multiple_locales_hash_name
Feature/CTXAPI-1831 multiple locales hash name
2 parents 87f5f17 + d7fa6a1 commit 6582abf

File tree

2 files changed

+267
-102
lines changed

2 files changed

+267
-102
lines changed

packages/mdctl-core/streams/section.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const _ = require('lodash'),
3939
NON_WRITABLE_KEYS = ['facet'],
4040
SectionsCreated = [],
4141
{ privatesAccessor } = require('@medable/mdctl-core-utils/privates'),
42-
hash = require('crypto').createHash('md5')
42+
crypto = require('crypto')
4343

4444
class ExportSection {
4545

@@ -273,6 +273,19 @@ class ExportSection {
273273
if (_.isArray(content.localizations)) {
274274
const name = `${content.object}.${content.type}.${content.name}`
275275
content.localizations.forEach((l, locIdx) => {
276+
let localeInName
277+
if (_.isArray(l.locale)) {
278+
if (l.locale.length > 1) {
279+
localeInName = crypto.createHash('md5').update(l.locale.join()).digest('hex')
280+
} else if (_.isEqual(l.locale, ['*'])) {
281+
localeInName = 'anyLocale'
282+
} else {
283+
localeInName = l.locale[0]
284+
}
285+
} else {
286+
localeInName = l.locale
287+
}
288+
276289
const nodes = jp.nodes(l, '$..content')
277290
nodes.forEach((n) => {
278291
const parentPath = ['$', 'localizations', locIdx]
@@ -283,21 +296,6 @@ class ExportSection {
283296
objectPath.push(i)
284297
objectPath.push('data')
285298
if (cnt.data) {
286-
let localeInName;
287-
if (_.isArray(l.locale)){
288-
if(l.locale.length > 1) {
289-
localeInName = hash.update(l.locale.join()).digest('hex')
290-
} else {
291-
if (_.isEqual(l.locale, ['*'])) {
292-
localeInName = 'anyLocale'
293-
} else {
294-
localeInName = l.locale[0]
295-
}
296-
}
297-
} else {
298-
localeInName = l.locale
299-
}
300-
301299
privatesAccessor(this).templateFiles.push({
302300
name: `${name}.${localeInName}.${cnt.name}`,
303301
ext: TEMPLATES_EXT[content.type][cnt.name],

0 commit comments

Comments
 (0)