t2ym / i18n-element

I18N Base Element for Lit and Polymer
Other
9 stars 1 forks source link

Preprocess json-data to data property for i18n-format #75

Closed t2ym closed 5 years ago

t2ym commented 5 years ago

Preprocess <json-data> to data property for i18n-format

Implement preprocess for https://github.com/t2ym/i18n-format/issues/16

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

Preprocessed Compound Template 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>
    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"
    ];