localization.messages
Messages in ICU MessageFormat, by key, in catalogs by language tag: the returned function formats a key in the catalog of the user's best language, which it reads at each call, so a component follows a change of language. A key that catalog lacks comes from the first catalog.
Verwendung
Translate text with plurals
import { HStack, Symbol, Text, localization } from 'kuito';
const t = localization.messages({
en: { inbox: '{count, plural, =0 {No messages} one {# message} other {# messages}}' },
ar: { inbox: '{count, plural, zero {لا رسائل} one {رسالة واحدة} other {# رسائل}}' },
});
export function Inbox() {
return (
<HStack paddingInlineStart={16} paddingInlineEnd={8} gap={8} alignItems="center">
<Symbol name={{ ios: 'tray', android: 'inbox' }} />
<Text>{t('inbox', { count: 3 })}</Text>
</HStack>
);
}Signaturen
<const C extends MessageCatalogs>(catalogs: C): (key: MessageKey<C>, values?: MessageValues) => stringTypparameter
| Name | Einschränkung | Standard |
|---|---|---|
C | Readonly<Record<string, Readonly<Record<string, string>>>> | — |
Parameter
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
catalogs | C | Ja | — |
Rückgabe
(key: MessageKey<C>, values?: MessageValues) => string
Generiert aus den öffentlichen TypeScript-Deklarationen: Signaturen, Props und Standardwerte stammen aus der geprüften Quelle, Beschreibungen aus deren JSDoc. Kein Standardwert ist erfunden.