@enonic/ui 1.2.0 → 1.3.0
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/README.md +35 -0
- package/dist/enonic-ui.cjs +1 -1
- package/dist/enonic-ui.es.js +121 -119
- package/dist/style.cjs +1 -1
- package/dist/style.es.js +1 -1
- package/dist/styles/preset.css +2 -2
- package/dist/styles/style.css +1 -1
- package/dist/styles/tokens.css +0 -2
- package/dist/types/components/combobox/combobox.phrases.d.ts +3 -0
- package/dist/types/components/date-picker/date-picker.phrases.d.ts +10 -0
- package/dist/types/components/dialog/dialog.phrases.d.ts +3 -0
- package/dist/types/components/search-field/search-field.phrases.d.ts +5 -0
- package/dist/types/components/stepper/stepper.phrases.d.ts +4 -0
- package/dist/types/components/time-picker/time-picker.phrases.d.ts +6 -0
- package/dist/types/components/toast/toast.phrases.d.ts +3 -0
- package/dist/types/components/tree-list/tree-list.phrases.d.ts +9 -0
- package/dist/types/i18n/index.d.ts +2 -0
- package/dist/types/i18n/phrases.d.ts +41 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/providers/i18n-provider.d.ts +26 -0
- package/dist/types/providers/index.d.ts +1 -0
- package/dist/types/providers/tree-list-provider.d.ts +1 -1
- package/dist/types/providers/virtualized-tree-list-provider.d.ts +1 -0
- package/dist/types/types/i18n.d.ts +15 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/utils/phrase.d.ts +7 -0
- package/package.json +17 -15
package/README.md
CHANGED
|
@@ -160,6 +160,41 @@ Optional peers, needed per feature:
|
|
|
160
160
|
| `react-virtuoso` | `VirtualizedTreeList` and other virtualized lists |
|
|
161
161
|
| `tw-animate-css` | Component animations on the `preset.css` path |
|
|
162
162
|
|
|
163
|
+
## Localization
|
|
164
|
+
|
|
165
|
+
Every label a component renders on its own — the close button of a `Dialog`, the placeholder of a
|
|
166
|
+
`SearchField`, the month navigation of a `DatePicker` — is English by default and keyed
|
|
167
|
+
`enonic.ui.<component>.<name>`. To render them in the application's words, hand `I18nProvider` one
|
|
168
|
+
function at the root. It receives the key and the library's English for it, and answers the
|
|
169
|
+
application's text or the English it was given:
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
import { I18nProvider, type Translate } from '@enonic/ui';
|
|
173
|
+
|
|
174
|
+
const translate: Translate = (key, { defaultValue, values = [] }) => {
|
|
175
|
+
const phrase = phrases[key];
|
|
176
|
+
if (phrase === undefined) return defaultValue;
|
|
177
|
+
|
|
178
|
+
return phrase.replace(/\{(\d+)\}/g, (placeholder, i) => String(values[Number(i)] ?? placeholder));
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
<I18nProvider translate={translate}>
|
|
182
|
+
<App />
|
|
183
|
+
</I18nProvider>;
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
A phrase the application supplies still carries the library's `{0}` placeholders, so fill them with
|
|
187
|
+
`values` — returning `phrases[key]` unformatted renders `Go to step {0}` verbatim. On a miss, return
|
|
188
|
+
`defaultValue`: never an empty string and never the key, or the `aria-label`s go blank.
|
|
189
|
+
|
|
190
|
+
`translate`'s identity is the only thing that re-renders the labels. Hoisting it out of the render is
|
|
191
|
+
right for a phrase bundle fixed at load; where the locale switches or the bundle arrives later, put
|
|
192
|
+
it in a `useMemo` keyed on that instead, or the labels keep their first wording.
|
|
193
|
+
|
|
194
|
+
`uiPhrases` lists every key with its English, for the application to add to its own phrase files
|
|
195
|
+
and check its bundle against. Texts the application supplies through props — a dialog title, an
|
|
196
|
+
item name — never pass through the provider.
|
|
197
|
+
|
|
163
198
|
## What's exported
|
|
164
199
|
|
|
165
200
|
Beyond the components, the package entry re-exports the hooks that drive them (roving tabindex, type-ahead, floating position, scroll lock, and more), the bundled icon set, context providers, shared types, and the `cn` class-merge helper.
|