Skip to content

Added a multi-language support and architecture - #16

Open
Elgoogko wants to merge 2 commits into
pablostanley:mainfrom
Elgoogko:main
Open

Added a multi-language support and architecture#16
Elgoogko wants to merge 2 commits into
pablostanley:mainfrom
Elgoogko:main

Conversation

@Elgoogko

Copy link
Copy Markdown

feat: add language support and translations for multiple languages (English and French)
Add .idea folder to .gitignore

Using a React hook, the application is now able to change its language for the better comfort of non-English users. It provides an architecture that makes it easy to add a new language.

#Add a new language

To add a new language to the application, you need to :

  1. create a new [lang].ts file in src/locales written with this template:
import {Translations} from "./types";

export const newLangName: Translations = {
   {/*Translations keys - if you're on VS Code or WebStorm, the IDE will automatically add the missing keys here*/}
}
  1. Go to src/locales/types.ts and change those two values by adding the name of your language:
export type Language = 'en' | 'fr' | 'newLangName'
export const LANG: Language[] = ['en', 'fr', 'newLangName']

#Use Translations

If you create a new component in the app, you need to use translations in the same way you use Theme colors: by using the Language provider.
In your component (can only be used if it's within the language provider), you can call the translations like this:

// src/components/MyComponent.tsx
export default function MyComponent() {
    const {t} = useTranslations()
    const theme = useTheme()

    return (
          <Text color={theme.primary}>{t.MY_COMPONENT_NAME}</Text>
);
}

And you add keys to the Translations Interface :

// src/locales/types.ts
{/*...*/}

export interface Translations {
 ...,
 MY_COMPONENT_NAME: string
}

Finally, in the English dictionary (or any dictionary you want), you can add :

import {Translations} from "./types";

export const en: Translations = {
 ...,
MY_COMPONENT_NAME: "My Component"
}

Note

While developing your component, use the hard-coded text in your component. The translation comes at the last step. Moreover, the English dictionary is the default fallback if a language dictionary is not complete or is missing keys to prevent blank / empty texts.

…nglish and french)

add .idea folder to .gitignore
…ictionnaries: if a key is missing, then the translation will return by default the english translation. It is supposed that the english dictionnary en.ts will always be updated and maintained compared to the others
@Elgoogko
Elgoogko marked this pull request as ready for review August 15, 2026 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant