NMF-earth / nmf-app

Understand and reduce your carbon footprint 🌱 iOS & Android.
https://nmf.earth
GNU General Public License v3.0
498 stars 156 forks source link

Synch mechanism with poeditor - (Sticker Reward 🎁) #225

Closed PierreBresson closed 3 years ago

PierreBresson commented 3 years ago

Inside scripts create a folder named poeditor and create translations.en, translations.fr etc (see supportedLanguages in App.tsx)

Write a script that will grab all translation strings from one language contained in all the corresponding json files (across screens and components 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 in translations.en, translations.fr... needed by screens/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...)

a2br commented 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.

PierreBresson commented 3 years ago

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).

a2br commented 3 years ago

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)

PierreBresson commented 3 years ago

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

a2br commented 3 years ago

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 🥱