Skip to content

Commit

Permalink
js: config.js: Refactor attribute name normalization for i18n data at…
Browse files Browse the repository at this point in the history
…tributes
  • Loading branch information
pkvach committed Apr 14, 2024
1 parent 66c7c65 commit 09a0ba8
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions isso/js/app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,24 @@ for (var i = 0; i < js.length; i++) {
var attr = js[i].attributes[j];
if (/^data-isso-/.test(attr.name)) {

// Normalize underscores to dashes so that language-specific
// strings can be caught better later on, e.g.
// data-isso-postbox-text-text-PT_BR becomes postbox-text-text-pt-br.
// Also note that attr.name only gives lowercase strings as per HTML
// spec, e.g. data-isso-FOO-Bar becomes foo-bar, but since the test
// environment's jest-environment-jsdom seemingly does not follow
// that convention, convert to lowercase here anyway.
const attrName = attr.name.substring(10)
.replace(/_/g, '-')
.toLowerCase()

// Replace escaped newline characters in the attribute value with actual newline characters
const attrValue = attr.value.replace(/\\n/g, '\n');

try {
// Normalize underscores to dashes so that language-specific
// strings can be caught better later on,
// e.g. data-isso-postbox-text-text-PT_BR becomes
// postbox-text-text-pt-br.
// Also note that attr.name only gives lowercase strings as per
// HTML spec, e.g. data-isso-FOO-Bar becomes foo-bar, but since
// the test environment's jest-environment-jsdom seemingly does
// not follow that convention, convert to lowercase here anyway.
config[attr.name.substring(10)
.replace(/_/g, '-')
.toLowerCase()] = JSON.parse(attrValue);
config[attrName] = JSON.parse(attrValue);
} catch (ex) {
config[attr.name.substring(10)
.replace(/_/g, '-')
.toLowerCase()] = attrValue;
config[attrName] = attrValue;
}
}
}
Expand Down

0 comments on commit 09a0ba8

Please sign in to comment.