t2ym/i18n-format

Add data property to shortcut JSON stringification and parsing for <json-data>

Closed this issue · 0 comments

t2ym commented

Add data property to shortcut JSON stringification and parsing for <json-data>

Preprocessed Compound Template Format

  • Generated viai18n-element/demo/gulpfile.js with useI18nFormatDataProperty = true

  • In order to avoid detours in JSON.stringify() and JSON.parse() processing for <json-data> contents, <i18n-format> element can take data 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 setting useI18nFormatDataProperty = true, disabled by setting useI18nFormatDataProperty = false in i18n-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"
    ];