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.
Utilisation
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>
);
}Signatures
<const C extends MessageCatalogs>(catalogs: C): (key: MessageKey<C>, values?: MessageValues) => stringParamètres de type
| Nom | Contrainte | Par défaut |
|---|---|---|
C | Readonly<Record<string, Readonly<Record<string, string>>>> | — |
Paramètres
| Nom | Type | Requis | Description |
|---|---|---|---|
catalogs | C | Oui | — |
Retourne
(key: MessageKey<C>, values?: MessageValues) => string
Généré depuis les déclarations TypeScript publiques : signatures, props et valeurs par défaut viennent de la source vérifiée, les descriptions de sa JSDoc. Aucune valeur par défaut n'est inventée.