Files
umami/src/components/hooks/useMessages.ts
T
Mike CaoandClaude Opus 4.6 50edb71687 Simplify i18n: remove old react-intl artifacts, rename formatMessage to t, replace FormattedMessage with t.rich().
- Rewrite messages.ts to plain string key maps (remove MessageDescriptor)
- Rewrite useMessages hook to expose t from useTranslations() directly
- Rename formatMessage → t across 193 consumer files
- Replace custom FormattedMessage component with next-intl t.rich()
- Update 52 language files to use rich text tags (<b>, <a>)
- Remove all direct imports from @/components/messages in favor of useMessages()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 11:19:04 -08:00

22 lines
543 B
TypeScript

import { useTranslations } from 'next-intl';
import { labels, messages } from '@/components/messages';
import type { ApiError } from '@/lib/types';
export function useMessages() {
const t = useTranslations();
const getMessage = (id: string) => t(`message.${id}`);
const getErrorMessage = (error: ApiError) => {
if (!error) {
return undefined;
}
const code = error?.code;
return code ? getMessage(code) : error?.message || 'Unknown error';
};
return { t, messages, labels, getMessage, getErrorMessage };
}