Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHORE] Change translation JSON format (Easy but lot of changes) #829

Open
Zagrios opened this issue Mar 9, 2025 · 1 comment
Open

[CHORE] Change translation JSON format (Easy but lot of changes) #829

Zagrios opened this issue Mar 9, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@Zagrios
Copy link
Owner

Zagrios commented Mar 9, 2025

Problem

At the beginning of the project, we chose this format for translations:

"search-bar": {
    "search-placeholder": "Search a map",
    "filters-btn": "Filters",
    "dropdown": {
        "export-maps": "Export maps",
        "delete-maps": "Delete maps",
        "delete-duplicate-maps": "Delete duplicates"
    }
},

So a translation key would be search-bar.dropdown.export-maps

This was a bad choice.
This format introduces a lot of duplication, makes it time-consuming to find the right place to add new translations, and complicates inferring the correct translation key to use in React components. Additionally, it increases the risk of using invalid translation keys.

Solution

We need to switch to this format for translations:

"Search a map": "Search a map",
"Filters": "Filters",
"Export maps": "Export maps"
"Delete maps": "Delete maps"
"Delete duplicates": "Delete duplicates"

(For the English translation, keys and values will almost always be the same)

With this format, there's no need to figure out where to place new translations : just add them at the end.
All duplicated translations will be merged into a single translation key.
We can infer a Translatable type directly from the translation file:
Image

And any invalid translation key will be handled by TypeScript:

Image

@Zagrios Zagrios added the enhancement New feature or request label Mar 9, 2025
@Zagrios Zagrios self-assigned this Mar 9, 2025
@AltyFox
Copy link
Contributor

AltyFox commented Mar 9, 2025

Certainly doesn't look nearly as pretty, but certainly does make it easier

@Zagrios Zagrios removed their assignment Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants