mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 14:17:13 +01:00
Use FormattedMessage. Updated icons. Fixed bugs.
This commit is contained in:
parent
3afe843461
commit
83a014e884
20 changed files with 129 additions and 84 deletions
|
|
@ -1,7 +1,22 @@
|
|||
import { useIntl } from 'react-intl';
|
||||
import { useIntl, FormattedMessage, type MessageDescriptor } from 'react-intl';
|
||||
import { messages, labels } from '@/components/messages';
|
||||
|
||||
export function useMessages() {
|
||||
type FormatMessage = (
|
||||
descriptor: MessageDescriptor,
|
||||
values?: Record<string, string | number | boolean | null | undefined>,
|
||||
opts?: any,
|
||||
) => string | null;
|
||||
|
||||
interface UseMessages {
|
||||
formatMessage: FormatMessage;
|
||||
messages: typeof messages;
|
||||
labels: typeof labels;
|
||||
getMessage: (id: string) => string;
|
||||
getErrorMessage: (error: unknown) => string | undefined;
|
||||
FormattedMessage: typeof FormattedMessage;
|
||||
}
|
||||
|
||||
export function useMessages(): UseMessages {
|
||||
const intl = useIntl();
|
||||
|
||||
const getMessage = (id: string) => {
|
||||
|
|
@ -21,15 +36,12 @@ export function useMessages() {
|
|||
};
|
||||
|
||||
const formatMessage = (
|
||||
descriptor: {
|
||||
id: string;
|
||||
defaultMessage: string;
|
||||
},
|
||||
values?: Record<string, string>,
|
||||
descriptor: MessageDescriptor,
|
||||
values?: Record<string, string | number | boolean | null | undefined>,
|
||||
opts?: any,
|
||||
) => {
|
||||
return descriptor ? intl.formatMessage(descriptor, values, opts) : null;
|
||||
};
|
||||
|
||||
return { formatMessage, messages, labels, getMessage, getErrorMessage };
|
||||
return { formatMessage, messages, labels, getMessage, getErrorMessage, FormattedMessage };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue