Use the useTranslator()
hook to access the underlying translate
method and gain additional control.
useTranslator()
hook provides access to the underlying translate
method, but you really shouldn’t be using it very often. However, it is helpful in niche situations where you need to translate text on the fly (outside of standard component text or hooks).
To use it, simply call the hook and extract the translate
method. Then, you can call the translate
method wherever you like in your code (such as in an effect).
It can be useful in scenarios where you need finer grain control over translations, but most scenarios can be addressed via the useTranslation()
hook.
Its first argument should be the string you’d like to translate. You can also provide additional options as the second argument to adjust how translations are handled (the same way you can control translations in the <TranslatedText />
component).
useTranslation()
and <TranslatedText />
and provides a finer level of control in certain situations.If the translation fails, it will fall back to the original string that was provided."translate" Method Usage
translate
method is very similar to the useTranslation()
hook and accepts the same options.context
“Track my progress” when the child string is “Track”.defaultLanguage
prop provided to the <TranslationProvider />
.Example: en-US
targetLanguage
prop provided to the <TranslationProvider />
(which defaults to the user’s detected locale).Example: es-ES