@quetzallabs/i18n-react-native
v0.1.14
Published
Quetzal Labs i18n Utilities Package for React Native
Downloads
4
Readme
Welcome to Quetzal!
This package contains all the utilities you need to get started using Quetzal.
To install: npm install --save @quetzallabs/i18n-react-native
Once installed, run npx quetzal-setup
Read more about how to use this package at: https://quetzal.mintlify.app/quickstart
This package relies on the use-intl provider to put translations into your app: https://www.npmjs.com/package/use-intl
The use-intl provider needs to be provided messages and a desired locale, which can be done with:
import { getLocaleAndMessages } from "@quetzallabs/i18n-react-native"; const { locale, messages } = await getLocaleAndMessages();
The t function
Text in your application is translated by wrapping it in a t function. This function is built on the next-intl t function: https://next-intl-docs.vercel.app/docs/usage/messages
For components:
import { useI18n } from "@quetzallabs/i18n-react-native"; const { t } = useI18n();
For server-side:
import { getI18nUtils } from "@quetzallabs/i18n-react-native"; const { t } = await getI18nUtils();
Example usage:
t("This text will be translated to multiple locales by Quetzal")
Once your application has some of its text in t functions, you can run npx quetzal-process-translations
. This command will send new text to be translated and fetch text that has been translated already.
This command should be executed before every build to ensure up-to-date translations are included.