Reputation: 123
I try to use t function of i18next outside of React Native component. In some places I need to use "t" in function which is defined not in component. I don't know what would be the best way to pass the "t" into such functions.
Currently I'm thinking of these options:
What option do you think is the simplest and the best?
So far I use useTranslation hook and sometimes importing "t" from i18n.js config file, but I need to stick to one method of importing "t".
Upvotes: 1
Views: 1061
Reputation: 64
I personally use the first option which works pretty well and don't add complexity to function's parameters
I personally do this inside utils files which do not contains any component:
import { t } from 'i18next';
export async function generateMailBody(user, isContact) {
const yourMessage = isContact ? t('Your_message') : t('Problem_description');
...
}
Upvotes: 1