Closed PierreBresson closed 3 years ago
So, we just have to get the translations from files like \app\screens\Emissions\translations\en.json
and write them into a JSON file? If that's the case, \app\utils\translations\resources.ts
has already done half of the job in importing the translations. It seems pretty easy at first glance; I'll be working on it.
Yes, have of the job is probably partially done: I don't know if resources.ts
will be useful, but probably script/generate-translation-files.js
is (see readme.md). But that's the trivial part, the second part will take a bit more time because you have to analyse the strings a bit (maybe using some regex could help).
Wait, I feel like I misunderstood the task... Here's what I've done so far. A simple script that gets all the translations from the existing translation JSONs to put them all together and store them into 1 JSON per language. It seemed too easy to be real. Also, it might seem stupid, but I don't know how to test it 😅 tsconfig.json
doesn't specify the outDir
, and tsc
doesn't compile anything; how am I supposed to compile and test?
import * as fs from "fs";
//! FETCHING ALL TRANSLATION FILES (code copied and adapted from '../resources.ts')
// Screens
import * as Act from "../../../screens/Act/translations";
import * as Budget from "../../../screens/Budget/translations";
import * as Emissions from "../../../screens/Emissions/translations";
import * as Settings from "../../../screens/Settings/translations";
import * as MonthlyBudget from "../../../screens/MonthlyBudget/translations";
import * as ComingSoon from "../../../screens/ComingSoon/translations";
import * as InfoModal from "../../../screens/InfoModal/translations";
import * as AddEmission from "../../../screens/AddEmission/translations";
import * as EmissionItem from "../../../screens/EmissionItem/translations";
import * as Intro from "../../../screens/Intro/translations";
import * as About from "../../../screens/About/translations";
import * as SupportUs from "../../../screens/SupportUs/translations";
import * as MyLocation from "../../../screens/MyLocation/translations";
import * as ActDetail from "../../../screens/ActDetail/translations";
// Components
import * as NoEmission from "../../../components/NoEmission/translations";
// Utils
import * as UI from "../../../utils/ui/translations";
//! PUTTING ALL TRANSLATIONS TOGETHER
// Languages
const existing_languages = ["en", "de", "fr", "sv", "pt", "es", "pl", "ru", "da"];
let language_objects = {};
existing_languages.forEach((language) => {
language_objects[language] = {
...UI[language],
...About[language],
...MonthlyBudget[language],
...NoEmission[language],
...Act[language],
...Budget[language],
...Emissions[language],
...Settings[language],
...InfoModal[language],
...AddEmission[language],
...EmissionItem[language],
...Intro[language],
...SupportUs[language],
...MyLocation[language],
...ActDetail[language],
};
});
//! WRITING JSONs
existing_languages.forEach((language) => {
fs.writeFile(
`${language}.json`,
JSON.stringify(language_objects[language]),
(err) => {
if (err) throw err;
console.log("✔", language);
}
);
});
(sorry for the code length)
It looks alright, for the first part of the task (but I haven't test it though) Since it's just a script helping us and won't be send to prod, it's okayish to not do any test for now
Fine, I've got this covered then. I'll continue the work tomorrow and open a PR draft. Could you officially assign me the issue please? Good night 🥱
Inside
scripts
create a folder namedpoeditor
and createtranslations.en
,translations.fr
etc (seesupportedLanguages
inApp.tsx
)Write a script that will grab all translation strings from one language contained in all the corresponding
json
files (acrossscreens
andcomponents
folders) and place these translation strings inside the translation language file.So in another words,
translations.en
should contain after running the script the following : { "ABOUT_SCREEN_TITLE": "About", ... "ACT_SCREEN_TAB_NAME": "Act", ... "NO_EMISSION_COMPONENT_TITLE": "Hi there 👋", ... }This should enable poeditor to pull all the strings easily.
Since poeditor will generate us the
translations.en
,translations.fr
with the new translated strings, we need a second script that will grab all the strings contained intranslations.en
,translations.fr
... needed byscreens/About/translation/en.json
,screens/About/translation/fr.json
and replace the corresponding strings.It should be doable without changing json files because I've just fixed the translations files wording
Don't forget to explain how to quickly run these scripts in the readme file 🙂
NB1 : this is could be a large and complicated task, probably not suitable for beginners. NB2 : due to spam, I won't assigned this task to anyone without previous contribution to this repo but PR are accepted, just have a look if there is no PR up and if this issue is not assigned to anyone.
Reward : I will be sending stickers (from the Kickstarter) by mail to the person doing this PR, for free, because managing translations has been extremely painful for me so far (a lot happening by hand to not loose translations...)