Because i18next is too big and it's must a wrapper for ReactJs.
So We use a general internationalization library for ReactJs (pure ReactJs). It's react-intl from formatjs(origin from Yahoo).
Before using that should be read official documents.
-
Update lang messages into
locale/{YOUR_LANG}/*.json -
Display this message with
JSXtemplate:import IntlMessages from 'components/IntlMessages'; <IntlMessages id="{MESSAGE_KEY}" />;
-
Using directly
get message by id(withoutJSXelement) withuseIntlMessage(MESSAGE_ID)Ex:
import useIntlMessage from 'hooks/UseIntlMessage'; <AsyncRoute path="/" asyncComponent={HomePage} title={useIntlMessage('page.meta.title.home')} description={useIntlMessage('page.meta.title.home')} />;
-
Using utils format functions:
- FormattedDate
- FormattedTime
- FormattedNumber
- FormattedList
- FormattedDisplayName
- FormattedDateParts
- FormattedTimeParts
- FormattedDateTimeRange ... See more from official public interface
Ex:
import { useIntl } from 'react-intl'; const intl = useIntl(); intl.formatDate(new Date();
Ant Design components support locale languages. AUTO injected.