Files
node-factorio-recipes/components/shared/I18n/I18n.tsx
Sebastian Seedorf 3fea0f851f Added German language
2022-08-20 00:30:49 +02:00

21 lines
713 B
TypeScript

import { ComponentProps, FC } from 'react'
import { FormattedMessage, IntlShape } from 'react-intl'
import { useMessages } from '../../../src/i18n'
import { FormatXMLElementFn, PrimitiveType } from 'intl-messageformat'
interface Props extends ComponentProps<typeof FormattedMessage> {
id: keyof ReturnType<typeof useMessages>['en']
}
export const I18n: FC<Props> = ({ children, ...props }) => {
return <FormattedMessage {...props}>{children}</FormattedMessage>
}
export const i18n = (
intl: IntlShape,
id: keyof ReturnType<typeof useMessages>['en'],
values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>
) => {
return intl.formatMessage({ id }, values, { ignoreTag: true })
}