To add i18n text and translations to your component, you can follow these steps:
Inside your component, add the English text as plain strings directly in the JSX code or assign them to variables/constants. For example:
⚠️ DANGER The variable name must be
t
. Otherwise, the translation will not be detected by i18next-parser introduced below.
import { useT } from "@react/i18n"
// ...
// inside React component
const t = useT();
return (
<Text size="s">
{t("We like maps")}
</Text>
);
After adding the English text to your component, you can regenerate the i18n translation files by following these steps:
Open your terminal or command prompt.
Navigate to the root directory of your Re:Earth project.
Run the following command:
yarn i18n
This command will execute the i18next-parser
tool, which will parse your codebase for text marked for translation and update the translation files accordingly.
The translation files will be regenerated based on the updated source code. Existing translations will be retained, and new text will be added for translation.
By running the yarn i18n
command, you ensure that your translation files are up to date with the latest changes in the codebase, allowing you to manage translations effectively in Re:Earth.
Once you have regenerated the i18n translation files, you can proceed to update the translations for your new text. Here's how you can do it:
src/i18n/translations/en.yml
file in a text editor.'We like maps'
.ja.yml
file, which contains the translations for the Japanese language.