Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
t2ym opened this issue Mar 17, 2019 · 0 comments
Closed

Comments

@t2ym
Copy link
Owner

t2ym commented Mar 17, 2019

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"
    ];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant