Add data property to shortcut JSON stringification and parsing for <json-data>
Closed this issue · 0 comments
Add data
property to shortcut JSON stringification and parsing for <json-data>
Preprocessed Compound Template Format
-
Generated via
i18n-element/demo/gulpfile.js
withuseI18nFormatDataProperty = true
-
In order to avoid detours in
JSON.stringify()
andJSON.parse()
processing for<json-data>
contents,<i18n-format>
element can takedata
property to set the parsed JSON data object directly and shortcut JSON stringificaton and parsing for<json-data>
. -
i18n-element/demo/gulpfile.js
can preprocess target tagged template literals to this optimized format. This preprocessing can be enabled by settinguseI18nFormatDataProperty = true
, disabled by settinguseI18nFormatDataProperty = false
ini18n-element/demo/gulpfile.js
-
Format shown in an equivalent tagged template literal format
<i18n-format id="target" lang="${effectiveLang}" .data=${text['target']['0']}>
<json-data preprocessed></json-data>
<i18n-number lang="${effectiveLang}" offset="1">${this.recipients.length}</i18n-number>
<span>${this.recipients.0.gender}</span>
<span>${this.sender.name}</span>
<span>${this.recipients.0.name}</span>
<span>${text['target']['5']}</span>
</i18n-format>
- Extracted text data
text['target'] = [
{
"0": "You ({3}) gave no gifts.",
"1": {
"male": "You ({3}) gave him ({4}) {5}.",
"female": "You ({3}) gave her ({4}) {5}.",
"other": "You ({3}) gave them ({4}) {5}."
},
"one": {
"male": "You ({3}) gave him ({4}) and one other person {5}.",
"female": "You ({3}) gave her ({4}) and one other person {5}.",
"other": "You ({3}) gave them ({4}) and one other person {5}."
},
"other": "You ({3}) gave them ({4}) and {1} other people gifts."
},
"{{recipients.length}}",
"{{recipients.0.gender}}",
"{{sender.name}}",
"{{recipients.0.name}}",
"a gift"
];