t2ym / i18n-element

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

[3.0] Support lit-html and LitElement #61

Closed t2ym closed 5 years ago

t2ym commented 6 years ago

[3.0] Support lit-html and LitElement

Tasks

Notes

t2ym commented 5 years ago

I18N for lit-html

Highlights

Get Started

Example Project - PWA Starter Kit with I18N

Status

browser raw preprocessed bundled coverage
Chrome 72 ✔︎ ✔︎ ✔︎ ✔︎
Firefox 65 ✔︎ ✔︎ ✔︎ ✔︎
Safari 12 ✔︎ ✔︎ ✔︎ ✔︎
Safari 9 ✔︎ ✔︎ ✔︎ ✔︎
Edge 17 ✔︎ ✔︎ ✔︎ ✔︎
IE 11 ✔︎ ✔︎ ✔︎ ✔︎

Preprocessed HTML Templates

const binding = bind('get-message', import.meta);
html([
    '<!-- localizable -->',
    '<div>',
    '</div><div>',
    '</div>'
  ], ...bind(('get-message', binding), (_bind, text, model, effectiveLang) => [
    _bind,
    text['div'],
    getMutatingMessage()
  ], {
    'meta': {},
    'model': {},
    'div': 'message'
  }));
html([
      '<!-- localizable -->',
      '\n      <style>\n        :host {\n          display: block;\n          width: 100%;\n        }\n        world-clock {\n          display: flow;\n          max-width: 300px;\n        }\n      </style>\n      <div>',
      '</div>\n      ',
      '\n    '
    ], ...bind(this, (_bind, text, model, effectiveLang) => [
      _bind,
      text['div_1'],
      repeat(this.timezones, item => item, (item, index) => html`<world-clock .timezone=${ item }></world-clock>`)
    ], {
      'meta': {},
      'model': {},
      'div_1': 'World Clocks'
    }));
html([
      '<!-- localizable -->',
      '\n      <style>\n        :host {\n          display: block;\n          width: 100%;\n          max-width: 350px;\n          padding: 2px;\n        }\n      </style>\n      <div><i18n-format lang="',
      '"><span>',
      '</span><span slot="1">',
      '</span><button @click="',
      '" slot="2">',
      '</button><button @click="',
      '" slot="3">',
      '</button></i18n-format></div>\n      ',
      '\n    '
    ], ...bind(this, 'world-clock', (_bind, text, model, effectiveLang) => [
      _bind,
      effectiveLang,
      text['div_1']['0'],
      (this.timezone < 0 ? '' : '+') + this.timezone / 60,
      () => this.timezone -= 60,
      text['div_1']['2'],
      () => this.timezone += 60,
      text['div_1']['3'],
      super.render()
    ], {
      'meta': {},
      'model': {},
      'div_1': [
        ' Timezone: GMT{1}\n        {2}\n        {3} ',
        '{{parts.0}}',
        '-1h',
        '+1h'
      ]
    }));
html([
      '<!-- localizable -->',
      '\n      <style>\n        :host {\n          display: block;\n        }\n        .square {\n          position: relative;\n          width: 100%;\n          height: 0;\n          padding-bottom: 100%;\n        }\n        \n        svg {\n          position: absolute;\n          width: 100%;\n          height: 100%;\n        }\n        \n        .clock-face {\n          stroke: #333;\n          fill: white;\n        }\n        \n        .minor {\n          stroke: #999;\n          stroke-width: 0.5;\n        }\n        \n        .major {\n          stroke: #333;\n          stroke-width: 1;\n        }\n        \n        .hour {\n          stroke: #333;\n        }\n        \n        .minute {\n          stroke: #666;\n        }\n        \n        .second, .second-counterweight {\n          stroke: rgb(180,0,0);\n        }\n        \n        .second-counterweight {\n          stroke-width: 3;\n        }\n      </style>\n      <div id="target" @click="',
      '" .property="',
      '" attr="',
      '" ?enabled-boolean-attr="',
      '" ?disabled-boolean-attr="',
      '" i18n-target-attr="',
      '"><i18n-format lang="',
      '"><span>',
      '</span><span slot="1">',
      '</span><span slot="2">',
      '</span></i18n-format></div>\n      <div>',
      '</div>\n      <div class="square"> <!-- so the SVG keeps its aspect ratio -->\n        \n        <svg viewBox="0 0 100 100">\n          \n          <!-- first create a group and move it to 50,50 so\n              all co-ords are relative to the center -->\n          <g transform="translate(50,50)">\n            <circle class="clock-face" r="48"></circle>\n            <g>',
      '</g><!-- g tag to avoid i18n-format conversion -->\n            <g>',
      '</g><!-- g tag to avoid i18n-format conversion -->\n\n            <!-- hour hand -->\n            <line class="hour" y1="2" y2="-20" transform="rotate(',
      ')"></line>\n    \n            <!-- minute hand -->\n            <line class="minute" y1="4" y2="-30" transform="rotate(',
      ')"></line>\n    \n            <!-- second hand -->\n            <g transform="rotate(',
      ')">\n              <line class="second" y1="10" y2="-38"></line>\n              <line class="second-counterweight" y1="10" y2="2"></line>\n            </g>\n          </g>\n        </svg>\n      </div>\n    '
    ], ...bind(this, 'lit-clock', (_bind, text, model, effectiveLang) => [
      _bind,
      event => {
        let div = event.composedPath().filter(el => el.id === 'target')[0];
        alert('div.outerHTML = ' + div.outerHTML + ' div.property = ' + div.property + ' div.getAttribute("attr") = ' + div.getAttribute('attr') + ' div.getAttribute("i18n-target-attr") = ' + div.getAttribute('i18n-target-attr'));
      },
      'property value',
      'attr value',
      true,
      false,
      model['target']['i18n-target-attr'],
      effectiveLang,
      text['target']['0'],
      this.date.getHours(),
      this.date.getMinutes(),
      getMessage(),
      minuteTicks,
      hourTicks,
      30 * this.date.getHours() + this.date.getMinutes() / 2,
      6 * this.date.getMinutes() + this.date.getSeconds() / 10,
      6 * this.date.getSeconds()
    ], {
      'meta': {},
      'model': { 'target': { 'i18n-target-attr': 'I18N target attribute value' } },
      'target': [
        'Time: {1}:{2}',
        '{{parts.5}}',
        '{{parts.6}}'
      ]
    }));

Issues