@lion/ui 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/core/test/SlotMixin.test.js +28 -21
- package/components/drawer/src/LionDrawer.js +217 -0
- package/components/drawer/src/drawerStyle.js +59 -0
- package/components/drawer/test/lion-drawer.test.js +109 -0
- package/components/localize/src/number/parseNumber.js +15 -36
- package/components/localize/test/number/parseNumber.test.js +3 -12
- package/custom-elements.json +743 -0
- package/dist-types/components/drawer/src/LionDrawer.d.ts +67 -0
- package/dist-types/components/drawer/src/LionDrawer.d.ts.map +1 -0
- package/dist-types/components/drawer/src/drawerStyle.d.ts +2 -0
- package/dist-types/components/drawer/src/drawerStyle.d.ts.map +1 -0
- package/dist-types/components/drawer/test/lion-drawer.test.d.ts +3 -0
- package/dist-types/components/drawer/test/lion-drawer.test.d.ts.map +1 -0
- package/dist-types/components/localize/src/number/parseNumber.d.ts.map +1 -1
- package/dist-types/exports/define/lion-drawer.d.ts +2 -0
- package/dist-types/exports/define/lion-drawer.d.ts.map +1 -0
- package/dist-types/exports/drawer.d.ts +2 -0
- package/dist-types/exports/drawer.d.ts.map +1 -0
- package/dist-types/tsconfig.tsbuildinfo +1 -1
- package/docs/components/accordion/index.md +3 -0
- package/docs/components/accordion/overview.md +129 -0
- package/docs/components/accordion/reference.md +47 -0
- package/docs/components/accordion/use-cases.md +252 -0
- package/docs/components/button/examples.md +30 -0
- package/docs/components/button/index.md +3 -0
- package/docs/components/button/overview.md +30 -0
- package/docs/components/button/src/icon.svg.js +5 -0
- package/docs/components/button/use-cases.md +106 -0
- package/docs/components/calendar/index.md +3 -0
- package/docs/components/calendar/overview.md +49 -0
- package/docs/components/calendar/use-cases.md +192 -0
- package/docs/components/checkbox-group/index.md +3 -0
- package/docs/components/checkbox-group/overview.md +40 -0
- package/docs/components/checkbox-group/use-cases.md +256 -0
- package/docs/components/collapsible/assets/CustomCollapsible.js +113 -0
- package/docs/components/collapsible/assets/applyDemoCollapsibleStyles.js +37 -0
- package/docs/components/collapsible/examples.md +83 -0
- package/docs/components/collapsible/index.md +3 -0
- package/docs/components/collapsible/overview.md +39 -0
- package/docs/components/collapsible/use-cases.md +79 -0
- package/docs/components/combobox/examples.md +153 -0
- package/docs/components/combobox/index.md +3 -0
- package/docs/components/combobox/overview.md +51 -0
- package/docs/components/combobox/src/LinkMixin.js +60 -0
- package/docs/components/combobox/src/demo-selection-display.js +191 -0
- package/docs/components/combobox/src/gh-combobox/gh-button.js +69 -0
- package/docs/components/combobox/src/gh-combobox/gh-combobox.js +508 -0
- package/docs/components/combobox/src/google-combobox/assets/google-clear-icon.js +9 -0
- package/docs/components/combobox/src/google-combobox/assets/google-search-icon.js +9 -0
- package/docs/components/combobox/src/google-combobox/assets/google-voice-search-icon.js +19 -0
- package/docs/components/combobox/src/google-combobox/assets/googlelogo_color_272x92dp.png +0 -0
- package/docs/components/combobox/src/google-combobox/google-combobox.js +460 -0
- package/docs/components/combobox/src/lazyRender.js +29 -0
- package/docs/components/combobox/src/levenshtein.js +95 -0
- package/docs/components/combobox/src/md-combobox/MdFieldMixin.js +341 -0
- package/docs/components/combobox/src/md-combobox/md-combobox.js +89 -0
- package/docs/components/combobox/src/md-combobox/md-input.js +5 -0
- package/docs/components/combobox/src/md-combobox/style/load-roboto.js +6 -0
- package/docs/components/combobox/src/md-combobox/style/md-ripple.js +81 -0
- package/docs/components/combobox/src/wa-combobox/wa-combobox.js +368 -0
- package/docs/components/combobox/use-cases.md +377 -0
- package/docs/components/dialog/index.md +3 -0
- package/docs/components/dialog/overview.md +63 -0
- package/docs/components/dialog/src/demo-dialog-style.js +3 -0
- package/docs/components/dialog/src/demoStyle.js +39 -0
- package/docs/components/dialog/src/slots-dialog-content.js +32 -0
- package/docs/components/dialog/src/styled-dialog-content.js +38 -0
- package/docs/components/dialog/use-cases.md +154 -0
- package/docs/components/drawer/index.md +3 -0
- package/docs/components/drawer/overview.md +68 -0
- package/docs/components/drawer/src/demoStyle.js +71 -0
- package/docs/components/drawer/use-cases.md +194 -0
- package/docs/components/fieldset/index.md +3 -0
- package/docs/components/fieldset/overview.md +49 -0
- package/docs/components/fieldset/use-cases.md +185 -0
- package/docs/components/form/index.md +3 -0
- package/docs/components/form/overview.md +43 -0
- package/docs/components/form/use-cases.md +72 -0
- package/docs/components/icon/assets/bugs/bug01.svg.js +2 -0
- package/docs/components/icon/assets/bugs/bug02.svg.js +2 -0
- package/docs/components/icon/assets/bugs/bug05.svg.js +2 -0
- package/docs/components/icon/assets/bugs/bug06.svg.js +2 -0
- package/docs/components/icon/assets/bugs/bug08.svg.js +2 -0
- package/docs/components/icon/assets/bugs/bug12.svg.js +2 -0
- package/docs/components/icon/assets/bugs/bug19.svg.js +2 -0
- package/docs/components/icon/assets/bugs/bug23.svg.js +2 -0
- package/docs/components/icon/assets/bugs/bug24.svg.js +2 -0
- package/docs/components/icon/assets/iconset-bugs.js +11 -0
- package/docs/components/icon/assets/iconset-misc.js +3 -0
- package/docs/components/icon/assets/iconset-space.js +31 -0
- package/docs/components/icon/assets/misc/arrowLeft.svg.js +6 -0
- package/docs/components/icon/assets/space/aliens-spaceship.svg.js +2 -0
- package/docs/components/icon/assets/space/meteor.svg.js +2 -0
- package/docs/components/icon/assets/space/moon-flag.svg.js +2 -0
- package/docs/components/icon/assets/space/moon.svg.js +2 -0
- package/docs/components/icon/assets/space/night.svg.js +2 -0
- package/docs/components/icon/assets/space/orbit.svg.js +2 -0
- package/docs/components/icon/assets/space/planet.svg.js +2 -0
- package/docs/components/icon/assets/space/robot.svg.js +2 -0
- package/docs/components/icon/assets/space/rocket.svg.js +2 -0
- package/docs/components/icon/assets/space/satellite.svg.js +2 -0
- package/docs/components/icon/assets/space/signal.svg.js +2 -0
- package/docs/components/icon/assets/space/space-helmet.svg.js +2 -0
- package/docs/components/icon/assets/space/sun.svg.js +2 -0
- package/docs/components/icon/assets/space/telescope.svg.js +2 -0
- package/docs/components/icon/index.md +3 -0
- package/docs/components/icon/overview.md +40 -0
- package/docs/components/icon/use-cases.md +93 -0
- package/docs/components/index.md +7 -0
- package/docs/components/input/index.md +3 -0
- package/docs/components/input/overview.md +36 -0
- package/docs/components/input/use-cases.md +77 -0
- package/docs/components/input-amount/index.md +3 -0
- package/docs/components/input-amount/overview.md +49 -0
- package/docs/components/input-amount/use-cases.md +122 -0
- package/docs/components/input-date/index.md +3 -0
- package/docs/components/input-date/overview.md +39 -0
- package/docs/components/input-date/use-cases.md +83 -0
- package/docs/components/input-datepicker/index.md +3 -0
- package/docs/components/input-datepicker/overview.md +42 -0
- package/docs/components/input-datepicker/use-cases.md +78 -0
- package/docs/components/input-email/index.md +3 -0
- package/docs/components/input-email/overview.md +32 -0
- package/docs/components/input-email/use-cases.md +48 -0
- package/docs/components/input-iban/index.md +3 -0
- package/docs/components/input-iban/overview.md +37 -0
- package/docs/components/input-iban/use-cases.md +102 -0
- package/docs/components/input-range/index.md +3 -0
- package/docs/components/input-range/overview.md +34 -0
- package/docs/components/input-range/use-cases.md +108 -0
- package/docs/components/input-stepper/index.md +3 -0
- package/docs/components/input-stepper/overview.md +36 -0
- package/docs/components/input-stepper/use-cases.md +41 -0
- package/docs/components/input-tel/index.md +3 -0
- package/docs/components/input-tel/overview.md +62 -0
- package/docs/components/input-tel/src/h-region-code-table.js +109 -0
- package/docs/components/input-tel/use-cases.md +307 -0
- package/docs/components/input-tel-dropdown/examples.md +32 -0
- package/docs/components/input-tel-dropdown/index.md +3 -0
- package/docs/components/input-tel-dropdown/overview.md +38 -0
- package/docs/components/input-tel-dropdown/src/intl-input-tel-dropdown.js +127 -0
- package/docs/components/input-tel-dropdown/use-cases.md +159 -0
- package/docs/components/listbox/index.md +3 -0
- package/docs/components/listbox/overview.md +42 -0
- package/docs/components/listbox/src/listboxData.js +65 -0
- package/docs/components/listbox/use-cases.md +147 -0
- package/docs/components/pagination/index.md +3 -0
- package/docs/components/pagination/overview.md +29 -0
- package/docs/components/pagination/use-cases.md +99 -0
- package/docs/components/progress-indicator/assets/my-determinate-progress-bar.js +30 -0
- package/docs/components/progress-indicator/assets/my-indeterminate-progress-spinner.js +55 -0
- package/docs/components/progress-indicator/examples.md +125 -0
- package/docs/components/progress-indicator/index.md +3 -0
- package/docs/components/progress-indicator/overview.md +36 -0
- package/docs/components/radio-group/index.md +3 -0
- package/docs/components/radio-group/overview.md +46 -0
- package/docs/components/radio-group/use-cases.md +140 -0
- package/docs/components/select/index.md +3 -0
- package/docs/components/select/overview.md +44 -0
- package/docs/components/select/use-cases.md +55 -0
- package/docs/components/select-rich/examples.md +31 -0
- package/docs/components/select-rich/index.md +3 -0
- package/docs/components/select-rich/overview.md +46 -0
- package/docs/components/select-rich/src/flagStyles.js +1250 -0
- package/docs/components/select-rich/src/flags.png +0 -0
- package/docs/components/select-rich/src/flags@2x.png +0 -0
- package/docs/components/select-rich/src/intl-select-rich.js +194 -0
- package/docs/components/select-rich/src/regionMetaList.js +1717 -0
- package/docs/components/select-rich/use-cases.md +370 -0
- package/docs/components/steps/index.md +3 -0
- package/docs/components/steps/overview.md +63 -0
- package/docs/components/steps/use-cases.md +163 -0
- package/docs/components/switch/index.md +3 -0
- package/docs/components/switch/overview.md +75 -0
- package/docs/components/switch/reference.md +39 -0
- package/docs/components/switch/use-cases.md +76 -0
- package/docs/components/tabs/examples.md +23 -0
- package/docs/components/tabs/index.md +3 -0
- package/docs/components/tabs/overview.md +48 -0
- package/docs/components/tabs/src/lea-tab-panel.js +24 -0
- package/docs/components/tabs/src/lea-tab.js +45 -0
- package/docs/components/tabs/src/lea-tabs.js +28 -0
- package/docs/components/tabs/use-cases.md +219 -0
- package/docs/components/textarea/index.md +3 -0
- package/docs/components/textarea/overview.md +35 -0
- package/docs/components/textarea/use-cases.md +95 -0
- package/docs/components/tooltip/examples.md +39 -0
- package/docs/components/tooltip/index.md +3 -0
- package/docs/components/tooltip/overview.md +44 -0
- package/docs/components/tooltip/use-cases.md +208 -0
- package/docs/fundamentals/index.md +19 -0
- package/docs/fundamentals/node-tools/babel-plugin-extend-docs/index.md +1 -0
- package/docs/fundamentals/node-tools/babel-plugin-extend-docs/overview.md +233 -0
- package/docs/fundamentals/node-tools/index.md +1 -0
- package/docs/fundamentals/node-tools/providence-analytics/LocalConfiguration.md +68 -0
- package/docs/fundamentals/node-tools/providence-analytics/QueryResult.md +111 -0
- package/docs/fundamentals/node-tools/providence-analytics/analyzer.md +69 -0
- package/docs/fundamentals/node-tools/providence-analytics/assets/_mermaid.svg.js +1202 -0
- package/docs/fundamentals/node-tools/providence-analytics/dashboard.md +22 -0
- package/docs/fundamentals/node-tools/providence-analytics/index.md +1 -0
- package/docs/fundamentals/node-tools/providence-analytics/overview.md +192 -0
- package/docs/fundamentals/node-tools/publish-docs/index.md +1 -0
- package/docs/fundamentals/node-tools/publish-docs/overview.md +136 -0
- package/docs/fundamentals/node-tools/remark-extend/index.md +1 -0
- package/docs/fundamentals/node-tools/remark-extend/overview.md +274 -0
- package/docs/fundamentals/node-tools/rocket-preset-extend-lion-docs/index.md +1 -0
- package/docs/fundamentals/node-tools/rocket-preset-extend-lion-docs/overview.md +285 -0
- package/docs/fundamentals/rationales/TypeScript.md +18 -0
- package/docs/fundamentals/rationales/index.md +1 -0
- package/docs/fundamentals/rationales/side-effects.md +203 -0
- package/docs/fundamentals/rationales/versioning.md +35 -0
- package/docs/fundamentals/systems/core/index.md +3 -0
- package/docs/fundamentals/systems/core/overview.md +85 -0
- package/docs/fundamentals/systems/form/assets/FormatMixinDiagram-1.svg +1 -0
- package/docs/fundamentals/systems/form/assets/FormatMixinDiagram-2.svg +1 -0
- package/docs/fundamentals/systems/form/assets/FormatMixinDiagram-3.svg +84 -0
- package/docs/fundamentals/systems/form/assets/h-output.js +155 -0
- package/docs/fundamentals/systems/form/formatting-and-parsing.md +245 -0
- package/docs/fundamentals/systems/form/index.md +3 -0
- package/docs/fundamentals/systems/form/interaction-states.md +177 -0
- package/docs/fundamentals/systems/form/model-value.md +35 -0
- package/docs/fundamentals/systems/form/overview.md +82 -0
- package/docs/fundamentals/systems/form/styling.md +101 -0
- package/docs/fundamentals/systems/form/use-cases.md +156 -0
- package/docs/fundamentals/systems/form/validate.md +929 -0
- package/docs/fundamentals/systems/icon/index.md +3 -0
- package/docs/fundamentals/systems/icon/overview.md +124 -0
- package/docs/fundamentals/systems/index.md +1 -0
- package/docs/fundamentals/systems/localize/assets/all-locales.js +437 -0
- package/docs/fundamentals/systems/localize/assets/en-AU.js +6 -0
- package/docs/fundamentals/systems/localize/assets/en-GB.js +6 -0
- package/docs/fundamentals/systems/localize/assets/en-US.js +6 -0
- package/docs/fundamentals/systems/localize/assets/en.js +4 -0
- package/docs/fundamentals/systems/localize/assets/nl-BE.js +6 -0
- package/docs/fundamentals/systems/localize/assets/nl-NL.js +6 -0
- package/docs/fundamentals/systems/localize/assets/nl.js +4 -0
- package/docs/fundamentals/systems/localize/dates.md +195 -0
- package/docs/fundamentals/systems/localize/index.md +3 -0
- package/docs/fundamentals/systems/localize/numbers.md +217 -0
- package/docs/fundamentals/systems/localize/overview.md +48 -0
- package/docs/fundamentals/systems/localize/rationale.md +62 -0
- package/docs/fundamentals/systems/localize/text.md +125 -0
- package/docs/fundamentals/systems/localize/use-cases.md +319 -0
- package/docs/fundamentals/systems/overlays/assets/applyDemoOverlayStyles.js +22 -0
- package/docs/fundamentals/systems/overlays/assets/demo-overlay-backdrop.js +48 -0
- package/docs/fundamentals/systems/overlays/assets/demo-overlay-system.js +42 -0
- package/docs/fundamentals/systems/overlays/assets/umbrella-form.js +133 -0
- package/docs/fundamentals/systems/overlays/configuration.md +453 -0
- package/docs/fundamentals/systems/overlays/form-integration.md +65 -0
- package/docs/fundamentals/systems/overlays/index.md +3 -0
- package/docs/fundamentals/systems/overlays/overview.md +118 -0
- package/docs/fundamentals/systems/overlays/rationale.md +232 -0
- package/docs/fundamentals/systems/overlays/scope.md +176 -0
- package/docs/fundamentals/systems/overlays/use-cases.md +699 -0
- package/docs/fundamentals/tools/ajax/assets/naga.json +9 -0
- package/docs/fundamentals/tools/ajax/assets/pabu.json +9 -0
- package/docs/fundamentals/tools/ajax/index.md +3 -0
- package/docs/fundamentals/tools/ajax/overview.md +128 -0
- package/docs/fundamentals/tools/ajax/use-cases.md +456 -0
- package/docs/fundamentals/tools/helpers/action-logger.md +165 -0
- package/docs/fundamentals/tools/helpers/index.md +3 -0
- package/docs/fundamentals/tools/helpers/overview.md +30 -0
- package/docs/fundamentals/tools/index.md +1 -0
- package/docs/fundamentals/tools/singleton-manager/index.md +3 -0
- package/docs/fundamentals/tools/singleton-manager/overview.md +304 -0
- package/docs/guides/how-to/create-a-custom-field.md +200 -0
- package/docs/guides/how-to/extend-a-native-input.md +66 -0
- package/docs/guides/how-to/get-started.md +77 -0
- package/docs/guides/how-to/index.md +1 -0
- package/docs/guides/index.md +34 -0
- package/docs/guides/principles/definitions-and-terms.md +41 -0
- package/docs/guides/principles/index.md +26 -0
- package/docs/guides/principles/scoped-elements.md +103 -0
- package/docs/guides/principles/styling.md +32 -0
- package/docs/guides/principles/subclasser-apis.md +28 -0
- package/docs/override.js +15 -0
- package/exports/define/lion-drawer.js +3 -0
- package/exports/drawer.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# Systems >> Localize >> Format Dates ||40
|
|
2
|
+
|
|
3
|
+
## Features
|
|
4
|
+
|
|
5
|
+
- Small file size
|
|
6
|
+
- Uses `Intl.DateFormat` but patches browser inconsistencies
|
|
7
|
+
|
|
8
|
+
## Formatting
|
|
9
|
+
|
|
10
|
+
With the `formatDate` you can safely display dates for all languages.
|
|
11
|
+
|
|
12
|
+
The input value is `new Date('1987/05/12')`.
|
|
13
|
+
|
|
14
|
+
```js script
|
|
15
|
+
import { css, html } from '@mdjs/mdjs-preview';
|
|
16
|
+
import { formatNumber, formatNumberToParts, formatDate } from '@lion/ui/localize.js';
|
|
17
|
+
import allLocales from './assets/all-locales.js';
|
|
18
|
+
|
|
19
|
+
const formatDateDemoStyle = css`
|
|
20
|
+
.demo-table {
|
|
21
|
+
border-collapse: collapse;
|
|
22
|
+
text-align: right;
|
|
23
|
+
}
|
|
24
|
+
.demo-table thead > tr {
|
|
25
|
+
border-bottom: 1px solid grey;
|
|
26
|
+
}
|
|
27
|
+
.demo-table thead > tr > :first-child,
|
|
28
|
+
.demo-table tbody > tr > :first-child,
|
|
29
|
+
.demo-table tfoot > tr > :first-child {
|
|
30
|
+
text-align: left;
|
|
31
|
+
}
|
|
32
|
+
.demo-table th,
|
|
33
|
+
.demo-table td {
|
|
34
|
+
padding: 8px;
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```js preview-story
|
|
40
|
+
export const formatting = () => html`
|
|
41
|
+
<style>
|
|
42
|
+
${formatDateDemoStyle}
|
|
43
|
+
</style>
|
|
44
|
+
<table class="demo-table">
|
|
45
|
+
<thead>
|
|
46
|
+
<tr>
|
|
47
|
+
<th>Output</th>
|
|
48
|
+
<th>Options</th>
|
|
49
|
+
<th>Code</th>
|
|
50
|
+
</tr>
|
|
51
|
+
</thead>
|
|
52
|
+
<tbody>
|
|
53
|
+
<tr>
|
|
54
|
+
<td>${formatDate(new Date('1987/05/12'))}</td>
|
|
55
|
+
<td>Default</td>
|
|
56
|
+
<td><code>formatDate(new Date('1987/05/12'))</code></td>
|
|
57
|
+
</tr>
|
|
58
|
+
<tr>
|
|
59
|
+
<td>
|
|
60
|
+
${formatDate(new Date('1987/05/12'), {
|
|
61
|
+
weekday: 'long',
|
|
62
|
+
year: 'numeric',
|
|
63
|
+
month: 'long',
|
|
64
|
+
day: '2-digit',
|
|
65
|
+
})}
|
|
66
|
+
</td>
|
|
67
|
+
<td>Date display</td>
|
|
68
|
+
<td>
|
|
69
|
+
<code
|
|
70
|
+
>formatDate(new Date(){weekday:'long',year:'numeric',month:'long',day:'2-digit'})</code
|
|
71
|
+
>
|
|
72
|
+
</td>
|
|
73
|
+
</tr>
|
|
74
|
+
<tr>
|
|
75
|
+
<td>
|
|
76
|
+
${formatDate(new Date('1987/05/12'), {
|
|
77
|
+
weekday: 'long',
|
|
78
|
+
month: 'long',
|
|
79
|
+
day: '2-digit',
|
|
80
|
+
})}
|
|
81
|
+
</td>
|
|
82
|
+
<td>Date without year</td>
|
|
83
|
+
<td>
|
|
84
|
+
<code>
|
|
85
|
+
formatDate(new Date('1987/05/12'), {weekday:'long',month:'long',day:'2-digit'})
|
|
86
|
+
</code>
|
|
87
|
+
</td>
|
|
88
|
+
</tr>
|
|
89
|
+
<tr>
|
|
90
|
+
<td>
|
|
91
|
+
${formatDate(new Date('1987/05/12'), {
|
|
92
|
+
weekday: 'long',
|
|
93
|
+
year: 'numeric',
|
|
94
|
+
day: '2-digit',
|
|
95
|
+
})}
|
|
96
|
+
</td>
|
|
97
|
+
<td>Date without month</td>
|
|
98
|
+
<td>
|
|
99
|
+
<code>
|
|
100
|
+
formatDate(new Date('1987/05/12'), {weekday:'long',year:'numeric',day:'2-digit'})
|
|
101
|
+
</code>
|
|
102
|
+
</td>
|
|
103
|
+
</tr>
|
|
104
|
+
<tr>
|
|
105
|
+
<td>
|
|
106
|
+
${formatDate(new Date('1987/05/12'), {
|
|
107
|
+
weekday: 'long',
|
|
108
|
+
month: 'long',
|
|
109
|
+
year: 'numeric',
|
|
110
|
+
})}
|
|
111
|
+
</td>
|
|
112
|
+
<td>Date without day</td>
|
|
113
|
+
<td>
|
|
114
|
+
<code>
|
|
115
|
+
formatDate(new Date('1987/05/12'), { weekday:'long',year:'numeric',month:'long' })
|
|
116
|
+
</code>
|
|
117
|
+
</td>
|
|
118
|
+
</tr>
|
|
119
|
+
<tr>
|
|
120
|
+
<td>${formatDate(new Date('1987/05/12'), { locale: 'nl-NL' })}</td>
|
|
121
|
+
<td>Locale</td>
|
|
122
|
+
<td><code>formatDate(new Date('1987/05/12'){ locale:'nl-NL' })</code></td>
|
|
123
|
+
</tr>
|
|
124
|
+
</tbody>
|
|
125
|
+
</table>
|
|
126
|
+
`;
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## List common locales
|
|
130
|
+
|
|
131
|
+
The input value is `new Date('1987/05/12')`.
|
|
132
|
+
Formatting happens via
|
|
133
|
+
|
|
134
|
+
```js
|
|
135
|
+
formatDate(new Date('1987/05/12'), { locale });
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
```js preview-story
|
|
139
|
+
export const listCommonLocales = () => html`
|
|
140
|
+
<style>
|
|
141
|
+
${formatDateDemoStyle}
|
|
142
|
+
</style>
|
|
143
|
+
<table class="demo-table">
|
|
144
|
+
<thead>
|
|
145
|
+
<tr>
|
|
146
|
+
<th>Locale</th>
|
|
147
|
+
<th>Output</th>
|
|
148
|
+
</tr>
|
|
149
|
+
</thead>
|
|
150
|
+
<tbody>
|
|
151
|
+
${['en-GB', 'en-US', 'nl-NL', 'nl-BE', 'fr-FR', 'de-DE'].map(
|
|
152
|
+
locale => html`
|
|
153
|
+
<tr>
|
|
154
|
+
<td>${locale}</td>
|
|
155
|
+
<td>${formatDate(new Date('1987/05/12'), { locale })}</td>
|
|
156
|
+
</tr>
|
|
157
|
+
`,
|
|
158
|
+
)}
|
|
159
|
+
</tbody>
|
|
160
|
+
</table>
|
|
161
|
+
`;
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## List all locales
|
|
165
|
+
|
|
166
|
+
The following list shows date formatting for all known locales.
|
|
167
|
+
|
|
168
|
+
The input value is `new Date('1987/05/12')`.
|
|
169
|
+
Formatting happens via
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
formatDate(new Date('1987/05/12'), { locale });
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
```js preview-story
|
|
176
|
+
export const listAllLocales = () => html`
|
|
177
|
+
<style>
|
|
178
|
+
${formatDateDemoStyle}
|
|
179
|
+
</style>
|
|
180
|
+
<table class="demo-table">
|
|
181
|
+
<tr>
|
|
182
|
+
<th>Locale</th>
|
|
183
|
+
<th>Output</th>
|
|
184
|
+
</tr>
|
|
185
|
+
${Object.keys(allLocales).map(
|
|
186
|
+
locale => html`
|
|
187
|
+
<tr>
|
|
188
|
+
<td>${locale}</td>
|
|
189
|
+
<td>${formatDate(new Date('1987/05/12'), { locale })}</td>
|
|
190
|
+
</tr>
|
|
191
|
+
`,
|
|
192
|
+
)}
|
|
193
|
+
</table>
|
|
194
|
+
`;
|
|
195
|
+
```
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# Systems >> Localize >> Format Numbers ||30
|
|
2
|
+
|
|
3
|
+
## Features
|
|
4
|
+
|
|
5
|
+
- Small file size
|
|
6
|
+
- Uses `Intl.NumberFormat` but patches browser inconsistencies
|
|
7
|
+
|
|
8
|
+
## Formatting
|
|
9
|
+
|
|
10
|
+
With the `formatNumber` you can safely display a number for all languages.
|
|
11
|
+
|
|
12
|
+
The input value is `1234.56`.
|
|
13
|
+
|
|
14
|
+
```js script
|
|
15
|
+
import { html, css } from '@mdjs/mdjs-preview';
|
|
16
|
+
import { formatNumber, formatNumberToParts } from '@lion/ui/localize.js';
|
|
17
|
+
import allLocales from './assets/all-locales.js';
|
|
18
|
+
|
|
19
|
+
const formatNumberDemoStyle = css`
|
|
20
|
+
.demo-table {
|
|
21
|
+
border-collapse: collapse;
|
|
22
|
+
text-align: right;
|
|
23
|
+
}
|
|
24
|
+
.demo-table thead > tr {
|
|
25
|
+
border-bottom: 1px solid grey;
|
|
26
|
+
}
|
|
27
|
+
.demo-table thead > tr > :first-child,
|
|
28
|
+
.demo-table tbody > tr > :first-child,
|
|
29
|
+
.demo-table tfoot > tr > :first-child {
|
|
30
|
+
text-align: left;
|
|
31
|
+
}
|
|
32
|
+
.demo-table th,
|
|
33
|
+
.demo-table td {
|
|
34
|
+
padding: 8px;
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
const value = 1234.56;
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```js preview-story
|
|
41
|
+
export const formatting = () => html`
|
|
42
|
+
<style>
|
|
43
|
+
${formatNumberDemoStyle}
|
|
44
|
+
</style>
|
|
45
|
+
<table class="demo-table">
|
|
46
|
+
<thead>
|
|
47
|
+
<tr>
|
|
48
|
+
<th>Options</th>
|
|
49
|
+
<th>Output</th>
|
|
50
|
+
<th>Code</th>
|
|
51
|
+
</tr>
|
|
52
|
+
</thead>
|
|
53
|
+
<tbody>
|
|
54
|
+
<tr>
|
|
55
|
+
<td>Default</td>
|
|
56
|
+
<td>${formatNumber(value)}</td>
|
|
57
|
+
<td></td>
|
|
58
|
+
</tr>
|
|
59
|
+
<tr>
|
|
60
|
+
<td>Currency symbol</td>
|
|
61
|
+
<td>
|
|
62
|
+
${formatNumber(value, {
|
|
63
|
+
style: 'currency',
|
|
64
|
+
currencyDisplay: 'symbol',
|
|
65
|
+
currency: 'EUR',
|
|
66
|
+
})}
|
|
67
|
+
</td>
|
|
68
|
+
<td>
|
|
69
|
+
<code
|
|
70
|
+
>formatNumber({ style: 'currency', currencyDisplay: 'symbol', currency: 'EUR' })</code
|
|
71
|
+
>
|
|
72
|
+
</td>
|
|
73
|
+
</tr>
|
|
74
|
+
<tr>
|
|
75
|
+
<td>Currency code</td>
|
|
76
|
+
<td>
|
|
77
|
+
${formatNumber(value, {
|
|
78
|
+
style: 'currency',
|
|
79
|
+
currencyDisplay: 'code',
|
|
80
|
+
currency: 'EUR',
|
|
81
|
+
})}
|
|
82
|
+
</td>
|
|
83
|
+
<td>
|
|
84
|
+
<code>formatNumber({ style: 'currency', currencyDisplay: 'code', currency: 'EUR' })</code>
|
|
85
|
+
</td>
|
|
86
|
+
</tr>
|
|
87
|
+
<tr>
|
|
88
|
+
<td>Locale</td>
|
|
89
|
+
<td>${formatNumber(value, { locale: 'nl-NL' })}</td>
|
|
90
|
+
<td><code>formatNumber({ locale: 'nl-NL' })</code></td>
|
|
91
|
+
</tr>
|
|
92
|
+
<tr>
|
|
93
|
+
<td>No decimals</td>
|
|
94
|
+
<td>
|
|
95
|
+
${formatNumber(value, {
|
|
96
|
+
minimumFractionDigits: 0,
|
|
97
|
+
maximumFractionDigits: 0,
|
|
98
|
+
})}
|
|
99
|
+
</td>
|
|
100
|
+
<td>
|
|
101
|
+
<code>formatNumber({ minimumFractionDigits: 0, maximumFractionDigits: 0, })</code>
|
|
102
|
+
</td>
|
|
103
|
+
</tr>
|
|
104
|
+
</tbody>
|
|
105
|
+
</table>
|
|
106
|
+
`;
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Formatting parts
|
|
110
|
+
|
|
111
|
+
`formatNumberToParts` allows to get individual parts of a number on all browsers.
|
|
112
|
+
|
|
113
|
+
The input value `1234.56` gets formatted via
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
formatNumberToParts(value, { style: 'currency', currency: 'EUR' });
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
```js preview-story
|
|
120
|
+
export const formattingParts = () => html`
|
|
121
|
+
<style>
|
|
122
|
+
${formatNumberDemoStyle}
|
|
123
|
+
</style>
|
|
124
|
+
<table class="demo-table">
|
|
125
|
+
<thead>
|
|
126
|
+
<tr>
|
|
127
|
+
<th>Part</th>
|
|
128
|
+
<th>Output</th>
|
|
129
|
+
</tr>
|
|
130
|
+
</thead>
|
|
131
|
+
<tbody>
|
|
132
|
+
${formatNumberToParts(1234.56, { style: 'currency', currency: 'EUR' }).map(
|
|
133
|
+
part => html`
|
|
134
|
+
<tr>
|
|
135
|
+
<td>${part.type}</td>
|
|
136
|
+
<td>${part.value}</td>
|
|
137
|
+
</tr>
|
|
138
|
+
`,
|
|
139
|
+
)}
|
|
140
|
+
</tbody>
|
|
141
|
+
</table>
|
|
142
|
+
`;
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## List common locales
|
|
146
|
+
|
|
147
|
+
The input value is `1234.56`.
|
|
148
|
+
Formatting happens via
|
|
149
|
+
|
|
150
|
+
```js
|
|
151
|
+
formatNumber(1234.56, { locale, style: 'currency', currency: 'EUR' });
|
|
152
|
+
formatNumber(1234.56, { locale, style: 'currency', currency: 'USD' });
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
```js preview-story
|
|
156
|
+
export const listCommonLocales = () => html`
|
|
157
|
+
<style>
|
|
158
|
+
${formatNumberDemoStyle}
|
|
159
|
+
</style>
|
|
160
|
+
<table class="demo-table">
|
|
161
|
+
<thead>
|
|
162
|
+
<tr>
|
|
163
|
+
<th>Locale</th>
|
|
164
|
+
<th>Output Euro</th>
|
|
165
|
+
<th>Output US Dollar</th>
|
|
166
|
+
</tr>
|
|
167
|
+
</thead>
|
|
168
|
+
<tbody>
|
|
169
|
+
${['en-GB', 'en-US', 'nl-NL', 'nl-BE', 'fr-FR', 'de-DE'].map(
|
|
170
|
+
locale => html`
|
|
171
|
+
<tr>
|
|
172
|
+
<td>${locale}</td>
|
|
173
|
+
<td>${formatNumber(1234.56, { locale, style: 'currency', currency: 'EUR' })}</td>
|
|
174
|
+
<td>${formatNumber(1234.56, { locale, style: 'currency', currency: 'USD' })}</td>
|
|
175
|
+
</tr>
|
|
176
|
+
`,
|
|
177
|
+
)}
|
|
178
|
+
</tbody>
|
|
179
|
+
</table>
|
|
180
|
+
`;
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## List all locales
|
|
184
|
+
|
|
185
|
+
The following list show number formatting for all known locales.
|
|
186
|
+
|
|
187
|
+
The input value is `1234.56`.
|
|
188
|
+
Formatting happens via
|
|
189
|
+
|
|
190
|
+
```js
|
|
191
|
+
formatNumber(1234.56, { locale, style: 'currency', currency: 'EUR' });
|
|
192
|
+
formatNumber(1234.56, { locale, style: 'currency', currency: 'USD' });
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
```js preview-story
|
|
196
|
+
export const listAllLocales = () => html`
|
|
197
|
+
<style>
|
|
198
|
+
${formatNumberDemoStyle}
|
|
199
|
+
</style>
|
|
200
|
+
<table class="demo-table">
|
|
201
|
+
<tr>
|
|
202
|
+
<th>Locale</th>
|
|
203
|
+
<th>Output Euro</th>
|
|
204
|
+
<th>Output US Dollar</th>
|
|
205
|
+
</tr>
|
|
206
|
+
${Object.keys(allLocales).map(
|
|
207
|
+
locale => html`
|
|
208
|
+
<tr>
|
|
209
|
+
<td>${locale}</td>
|
|
210
|
+
<td>${formatNumber(1234.56, { locale, style: 'currency', currency: 'EUR' })}</td>
|
|
211
|
+
<td>${formatNumber(1234.56, { locale, style: 'currency', currency: 'USD' })}</td>
|
|
212
|
+
</tr>
|
|
213
|
+
`,
|
|
214
|
+
)}
|
|
215
|
+
</table>
|
|
216
|
+
`;
|
|
217
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Systems >> Localize >> Overview ||10
|
|
2
|
+
|
|
3
|
+
Is meant to translate text into multiple languages.
|
|
4
|
+
In it's simplest form it is a function that returns the translated text for a namespace + key.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
- Uses es modules
|
|
9
|
+
- Formatting of numbers, amounts
|
|
10
|
+
- Formatting of dates
|
|
11
|
+
|
|
12
|
+
Further examples and a more in depth description can be found at the [Use Cases Page](https://github.com/ing-bank/lion/blob/fbf0bd22378e76aa4261c2a97faf8be4f5fc461e/docs/fundamentals/systems/localize/use-cases.md).
|
|
13
|
+
|
|
14
|
+
## Content
|
|
15
|
+
|
|
16
|
+
| Feature | Description |
|
|
17
|
+
| ---------------------------------------- | --------------------------------------------- |
|
|
18
|
+
| [Translate Text](https://github.com/ing-bank/lion/blob/fbf0bd22378e76aa4261c2a97faf8be4f5fc461e/docs/fundamentals/systems/localize/text.md) | Load and translate text in multiple languages |
|
|
19
|
+
| [Format Numbers](https://github.com/ing-bank/lion/blob/fbf0bd22378e76aa4261c2a97faf8be4f5fc461e/docs/fundamentals/systems/localize/numbers.md) | Format numbers in multiple languages |
|
|
20
|
+
| [Format Dates](https://github.com/ing-bank/lion/blob/fbf0bd22378e76aa4261c2a97faf8be4f5fc461e/docs/fundamentals/systems/localize/dates.md) | Format dates in multiple languages |
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm i --save @lion/ui
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import { localize } from '@lion/ui/localize.js';
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Example
|
|
33
|
+
|
|
34
|
+
The locale which will be loaded by default is accessed via the `localize.locale`.
|
|
35
|
+
|
|
36
|
+
The single source of truth for page's locale is `<html lang="my-LOCALE">`.
|
|
37
|
+
At the same time the interaction should happen via `localize.locale` getter/setter to be able to notify and react to the change.
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
import { localize } from '@lion/ui/localize.js';
|
|
41
|
+
|
|
42
|
+
localize.addEventListener('localeChanged', () => {
|
|
43
|
+
// do smth when data is loaded for a new locale
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// changes locale, syncs to `<html lang="es-ES">` and fires the event above
|
|
47
|
+
localize.locale = 'es-ES';
|
|
48
|
+
```
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Systems >> Localize >> Rationale ||60
|
|
2
|
+
|
|
3
|
+
## Requirements
|
|
4
|
+
|
|
5
|
+
- loading translations per a web component or a module scope
|
|
6
|
+
- loading translations lazily
|
|
7
|
+
- loading translations from an API
|
|
8
|
+
- bundling and injecting translations for improving the initial page load time
|
|
9
|
+
- using variables in translations
|
|
10
|
+
- formatting dates and numbers according to a user's locale
|
|
11
|
+
- changing the language on the page without a full reload
|
|
12
|
+
- using JavaScript standards
|
|
13
|
+
- compatibility with modern tools like rollup and webpack
|
|
14
|
+
- backwards compatibility with Polymer CLI
|
|
15
|
+
- integration with lit-html and LitElement
|
|
16
|
+
|
|
17
|
+
## Decision making
|
|
18
|
+
|
|
19
|
+
### Building block of the localization system
|
|
20
|
+
|
|
21
|
+
We chose ES modules as building blocks because:
|
|
22
|
+
|
|
23
|
+
- this is a future proof standard
|
|
24
|
+
- support for loading both statically and dynamically
|
|
25
|
+
- good support in tools like rollup and webpack
|
|
26
|
+
- reusability of same translations between dialects of the same language
|
|
27
|
+
|
|
28
|
+
We decided to split all translation data into immutable namespaces because:
|
|
29
|
+
|
|
30
|
+
- there is a need for scopes to have a fine control over data
|
|
31
|
+
- namespaces can be loaded individually and bundled too (if needed)
|
|
32
|
+
- it is possible to consistently load all translations for a new language without full page reload (immutability is a key prerequisite here)
|
|
33
|
+
|
|
34
|
+
### Localization of numbers and dates
|
|
35
|
+
|
|
36
|
+
We decided to use `<html lang>` as a source of truth for the locale value because:
|
|
37
|
+
|
|
38
|
+
- this is a standard place in HTML
|
|
39
|
+
- it allows to support different tools like Google Chrome translate
|
|
40
|
+
|
|
41
|
+
We chose `Intl MessageFormat` as a format for translation parts because:
|
|
42
|
+
|
|
43
|
+
- it is the most stable solution for the web
|
|
44
|
+
- it is being standardized at the moment
|
|
45
|
+
- it supports formatting dates and numbers out of the box
|
|
46
|
+
|
|
47
|
+
### Fallbacks
|
|
48
|
+
|
|
49
|
+
> Important: language-only locales are now removed, and cause an error if you try to use it. This is because language only locales cause bugs with date and number formatting. It also makes writing locale based tooling harder and more cumbersome.
|
|
50
|
+
|
|
51
|
+
We decided to have a fallback mechanism in case a dialect (e.g. `nl-NL.js`) is not defined, but generic language (e.g. `nl.js`) is, because we wanted to support legacy applications which used
|
|
52
|
+
|
|
53
|
+
[Polymer's AppLocalizeBehavior](https://polymer-library.polymer-project.org/3.0/docs/apps/localize) and could not instantly switch to using full dialects.
|
|
54
|
+
|
|
55
|
+
We decided to have a fallback locale (`en-GB` by default):
|
|
56
|
+
|
|
57
|
+
- so that an app can work (with English where the gaps are) until everything is translated to all supported languages
|
|
58
|
+
- to allow Google Chrome translate feature to work and use a reliable source for translations when a user asks the page to be translated to an unsupported language
|
|
59
|
+
|
|
60
|
+
### Switch statements in the loader functions
|
|
61
|
+
|
|
62
|
+
We add switch statements to each of the loader functions to be backwards compatible with Polymer CLI.
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Systems >> Localize >> Translate Text ||20
|
|
2
|
+
|
|
3
|
+
## As a function
|
|
4
|
+
|
|
5
|
+
```js script
|
|
6
|
+
import { html, render, LitElement } from '@mdjs/mdjs-preview';
|
|
7
|
+
import { localize, formatNumber, formatDate, LocalizeMixin } from '@lion/ui/localize.js';
|
|
8
|
+
import '@lion/ui/define-helpers/sb-locale-switcher.js';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```js preview-story
|
|
12
|
+
export const asFunction = () => {
|
|
13
|
+
const wrapper = document.createElement('div');
|
|
14
|
+
let message = 'Loading...';
|
|
15
|
+
function update() {
|
|
16
|
+
message = localize.msg('lit-html-example:body');
|
|
17
|
+
render(
|
|
18
|
+
html`
|
|
19
|
+
<p>${message}</p>
|
|
20
|
+
<sb-locale-switcher></sb-locale-switcher>
|
|
21
|
+
`,
|
|
22
|
+
wrapper,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
localize
|
|
26
|
+
.loadNamespace({
|
|
27
|
+
'lit-html-example': locale => import(`./assets/${locale}.js`),
|
|
28
|
+
})
|
|
29
|
+
.then(() => {
|
|
30
|
+
update();
|
|
31
|
+
});
|
|
32
|
+
localize.addEventListener('localeChanged', () => {
|
|
33
|
+
localize.loadingComplete.then(() => update());
|
|
34
|
+
});
|
|
35
|
+
return wrapper;
|
|
36
|
+
};
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
localize.msg('lit-html-example:body'); // for en-GB: I am from England
|
|
41
|
+
localize.msg('lit-html-example:body'); // for nl-NL: Ik kom uit Nederland
|
|
42
|
+
// ...
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Web Component
|
|
46
|
+
|
|
47
|
+
For use in a web component we have `LocalizeMixin` that lets you define namespaces and awaits loading of those translations.
|
|
48
|
+
|
|
49
|
+
```js preview-story
|
|
50
|
+
export const webComponent = () => {
|
|
51
|
+
class MessageExample extends LocalizeMixin(LitElement) {
|
|
52
|
+
static get localizeNamespaces() {
|
|
53
|
+
return [
|
|
54
|
+
{ 'lit-html-example': locale => import(`./assets/translations/${locale}.js`) },
|
|
55
|
+
...super.localizeNamespaces,
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
render() {
|
|
60
|
+
return html`
|
|
61
|
+
<div aria-live="polite">
|
|
62
|
+
<p>${localize.msg('lit-html-example:body')}</p>
|
|
63
|
+
</div>
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (!customElements.get('message-example')) {
|
|
68
|
+
customElements.define('message-example', MessageExample);
|
|
69
|
+
}
|
|
70
|
+
return html`
|
|
71
|
+
<message-example></message-example>
|
|
72
|
+
<sb-locale-switcher></sb-locale-switcher>
|
|
73
|
+
`;
|
|
74
|
+
};
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
class MessageExample extends LocalizeMixin(LitElement) {
|
|
79
|
+
render() {
|
|
80
|
+
return html`
|
|
81
|
+
<div aria-live="polite">
|
|
82
|
+
<p>${localize.msg('lit-html-example:body')}</p>
|
|
83
|
+
</div>
|
|
84
|
+
`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Google Translate integration
|
|
90
|
+
|
|
91
|
+
When Google Translate is enabled, it takes control of the html[lang] attribute.
|
|
92
|
+
Below, we find a simplified example that illustrates this.
|
|
93
|
+
|
|
94
|
+
### The problem
|
|
95
|
+
|
|
96
|
+
A developer initializes a page like this (and instructs localize to fetch data for `en-US` locale)
|
|
97
|
+
|
|
98
|
+
```html
|
|
99
|
+
<html lang="en-US"></html>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
If Google Translate is enabled and set to French, it will change html[lang]:
|
|
103
|
+
to `<html lang="fr">`
|
|
104
|
+
|
|
105
|
+
Now `localize` will fetch data for locale `fr`. There are two problems here:
|
|
106
|
+
|
|
107
|
+
- There might be no available data for locale `fr`
|
|
108
|
+
- Let's imagine data were loaded for `fr`. If Google Translate is turned off again,
|
|
109
|
+
the page content will consist of a combination of different locales.
|
|
110
|
+
|
|
111
|
+
### How to solve this
|
|
112
|
+
|
|
113
|
+
To trigger support for Google Translate, we need to configure two attributes
|
|
114
|
+
|
|
115
|
+
```html
|
|
116
|
+
<html lang="en-US" data-localize-lang="en-US"></html>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
- html[data-localize-lang] will be read by `localize` and used for fetching data
|
|
120
|
+
- html[lang] will be configured for accessibility purposes (it will makes sure the
|
|
121
|
+
page is accessible if localize would be lazy loaded).
|
|
122
|
+
|
|
123
|
+
When Google Translate is set to French, we get: `<html lang="fr" data-localize-lang="en-US">`
|
|
124
|
+
|
|
125
|
+
The page is accessible and `localize` will fetch the right resources
|