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.
Utilização
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>
);
}Assinaturas
<const C extends MessageCatalogs>(catalogs: C): (key: MessageKey<C>, values?: MessageValues) => stringParâmetros de tipo
| Nome | Restrição | Predefinição |
|---|---|---|
C | Readonly<Record<string, Readonly<Record<string, string>>>> | — |
Parâmetros
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
catalogs | C | Sim | — |
Devolve
(key: MessageKey<C>, values?: MessageValues) => string
Gerado a partir das declarações TypeScript públicas: assinaturas, props e predefinições vêm da fonte verificada, as descrições da sua JSDoc. Nenhuma predefinição é inventada.