i18nifty
GitHubHomeSandbox
  • 🏁Quick start
  • 🚄Asynchronous locale resources download
  • 📖API Reference
    • useLang
    • $lang
    • LocalizedString
    • useTranslation
    • getTranslation
  • ⬆️Migration guides
    • ⬆️v2 -> v3
Powered by GitBook
On this page

Was this helpful?

  1. API Reference

getTranslation

Use the translation function outside of React components.

PrevioususeTranslationNextMigration guides

Last updated 9 months ago

Was this helpful?

It's like useTranslation but it's not a hook, it can be used outside of React.

const { getTranslation } = createI18nApi(...);

const { t } = getTranslation("MyComponent");  

t("greating", { "who": "Jhon" });

Be mindfull, local resources are downloaded lazyly in with . If the resources aren't downloaded yet you'll get empty strings. Also you have to subscribe to language changes to get the updated values.

📖
asynchronous locale download