React i18n, check if translation exists?

Viewed 1504

Is there a way to check if a locale exists on react app ? Like a boolean true/false

1 Answers

Yes, you can check if your language variable exists with i18n.exists() method:

You can extract i18n from useTranslation hook.

const { t, i18n } = useTranslation();

Then call i18n.exists('my.key'), for example:

i18n.exists("common.values.active")

https://www.i18next.com/overview/api#exists

Related