pancakeswap / pancake-frontend

:pancakes: Pancake main features (farms, pools, IFO, lottery, profiles)
https://pancakeswap.finance
GNU General Public License v3.0
2.69k stars 3.55k forks source link

Automation of language translation #2763

Closed Serhioromano closed 2 years ago

Serhioromano commented 2 years ago

Is there an existing issue for this?

Is your feature request related to a problem you are facing?

Supporting multiple language project is a tedious task. It require synchronization oof all keys from the code to every locale file. If it is dome manually it takes a lot of time. Also in locale files hard to find new lines to be translated.

Describe the solution you'd like

I want to build CLI tool for developers. the main exec will be cake. This is proposed CLI API

$> cake lang-parse 

This command will go through all js, ts, tsx files and look for t('****') pattern. Then it will compare it against en-US.json and if any key that is not in a file it will add it there. So it will simplify developer routine. They do not need to work with locale json files. They just add t('Whatever is here') in a code and that is it. Later before build this command will run and parse everything and add those keys to locale files.

$> cake lang-sync

This command will open en-US.json and compare it's keys to every other file in locale folder and if any of those files, lacks some keys, those will be added at the end. Thus those who support translations may quickly find new untranslated lines and change it.

I'll add ./bin folder to project root. Create index.js file there and link as cake command in CLI. I'll use modern commander and other NPM libraries to build modern CLI. I'll add documentation instruction for developers how to use it.

I'm experienced developer.

How does this feature benefit PancakeSwap users and CAKE holders?

It is more CI\CD feature that speedup and automate multiple language support.

Anything else?

That is it.

memoyil commented 2 years ago

Currently there are unit tests that scan .ts .tsx files and take the strings in t('') and check them against translation.json. If there unknown keys the tests fail

https://github.com/pancakeswap/pancake-frontend/blob/develop/src/__tests__/config/translations.test.ts

Serhioromano commented 2 years ago

That is cool. Can we add sync too? So that we use translation.json as a source to sync all other locale files?

0xjojoex commented 2 years ago

We already have Crowdin, and we upload translation.json to auto translate. https://github.com/pancakeswap/pancake-frontend/pull/2730

Generally we don't edit {locale}.json directly, sometimes auto translation without context cause problem. so updating {locale}.json is fine, but we have to inform Crowdin folks to know about it

We also have a doc about [i18n](https://github.com/pancakeswap/pancake-frontend/blob/develop/doc/i18n.md. It is lacking some details though

Serhioromano commented 2 years ago

Excellent!