import { storiesOf, html } from '@open-wc/demoing-storybook'; import { html as litHtml } from '@lion/core'; import { LionLitElement } from '@lion/core/src/LionLitElement.js'; import { localize, LocalizeMixin, formatNumber, formatNumberToParts, getGroupSeparator, getDecimalSeparator, formatDate, parseDate, getDateFormatBasedOnLocale, } from '../index.js'; storiesOf('Localize System|Localize', module).add('lit component', () => { class LitHtmlExample extends LocalizeMixin(LionLitElement) { static get localizeNamespaces() { return [ { 'lit-html-example': locale => import(`./translations/${locale}.js`) }, ...super.localizeNamespaces, ]; } static get properties() { return { now: { type: 'Date', }, }; } render() { // this is as simple as localization can be in JavaScript // the Promise is used to delay inserting of the content until data is loaded // for the first time as soon as `now` is provided or changed, it will rerender // with a new value if locale is changed, there is a preconfigured listener // to rerender when new data is loaded all thanks to lit-html capabilities const headerDate = this.msgLit('lit-html-example:headerDate'); const headerNumber = this.msgLit('lit-html-example:headerNumber'); const date = this.now ? this.msgLit('lit-html-example:date', { now: this.now }) : ''; const time = this.now ? this.msgLit('lit-html-example:time', { now: this.now }) : ''; // dateFormat const options1 = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', }; options1.timeZone = 'UTC'; options1.timeZoneName = 'short'; const dateParse1 = parseDate('01-05-2012'); const dateParse2 = parseDate('12/05/2012'); const dateParse3 = parseDate('1-5-2017'); const dateFormat1 = formatDate(dateParse1, options1); const dateFormat2 = formatDate(dateParse2, options1); const dateFormat3 = formatDate(dateParse3, options1); const dateFormat = getDateFormatBasedOnLocale(); const datum = new Date(); const options2 = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', }; options2.timeZone = 'UTC'; options2.timeZoneName = 'short'; options2.locale = 'ja-JP-u-ca-japanese'; const dateFormatted = formatDate(datum, options2); // numberFormat const number1 = formatNumber(123456.789, { style: 'currency', currency: 'EUR', currencyDisplay: 'code', }); const formatNumberToParts1 = formatNumberToParts(123456.789, { style: 'currency', currency: 'EUR', currencyDisplay: 'code', }); let printParts1 = ''; for (let i = 0; i < formatNumberToParts1.length; i += 1) { printParts1 += `{ ${formatNumberToParts1[i].type}: ${formatNumberToParts1[i].value} }`; } const number2 = formatNumber(1234.5, { style: 'decimal' }); const formatNumberToParts2 = formatNumberToParts(1234.5, { style: 'decimal' }); let printParts2 = ''; for (let i = 0; i < formatNumberToParts2.length; i += 1) { printParts2 += `{ ${formatNumberToParts2[i].type}: ${formatNumberToParts2[i].value} }`; } const number3 = formatNumber(-1234.5, { style: 'currency', currency: 'EUR', currencyDisplay: 'code', }); const formatNumberToParts3 = formatNumberToParts(-1234.5, { style: 'currency', currency: 'EUR', currencyDisplay: 'code', }); let printParts3 = ''; for (let i = 0; i < formatNumberToParts3.length; i += 1) { printParts3 += `{ ${formatNumberToParts3[i].type}: ${formatNumberToParts3[i].value} }`; } const printGroupSeparator = getGroupSeparator(); const printDecimalSeparator = getDecimalSeparator(); return litHtml`
try 'demo:bar' as well
// // // //