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

Add translations-management scripts #231

Closed a2br closed 3 years ago

a2br commented 3 years ago

Summary

These scripts have been requested in issue https://github.com/NMF-earth/nmf-app/issues/225. There are 2 of them:

The reference translation files (ex: en.json) will be placed in /scripts/poeditor, next to the scripts.

They have been built to be flexible in case of future changes. For example, adding a new language only requires to add a 2-letters string in an array -- same for the translation dirs.

Notes

They have not been tested. Actually, I don't know how to do it. tsc doesn't compile anymore, even after some twists in tsconfig.json... 🤔 As always, let me know if you spot an error.

How to run them?

Once compiled using tsc, I assume you'd just have to run node ./path/to/script. As written above, I haven't tested them though, since the TypeScript Compiler doesn't compile. Tell me if I'm talking nonsense, I'm not familiar with React Native projects nor the way they are executed.

PierreBresson commented 3 years ago

Besides that, you don't have to care about yarn tsc, these scripts are not meant to be use by the app. They are used when I'm import / exporting translations via Poeditor, not when the app runs.

a2br commented 3 years ago

I was worrying about that because these are TS files, they need to be compiled to run; since they import stuff from other TS files, I thought all the files would need to be compiled together.

a2br commented 3 years ago

It means that you're trying to run the script as an ES2015 module, but Node.js supports CommonJS. This is a configuration error of TypeScript or whatever compiles its. To use the js import statements instead of the require statements, you'll need to add "type": "module" in package.json, although I recommend you to manually edit the files. As a reminder, you need to compile TypeScript files before you run them. The error you got may also appear when trying to run a TS file (which isn't supposed to be used).

If that's what happened, you should try tsc ./scripts/poeditor/spread-translation-files.ts and then the node command. It should work. I can't use the require statements in my commits because the ESLint CI would block that.

a2br commented 3 years ago

spread-translation-files.ts didn't need to be in TypeScript, so I changed it to JavaScript. The problem you encountered should be fixed now.

a2br commented 3 years ago

I'll keep working on group-translation-files.ts to make the same changes tomorrow evening, I'll have to manually import all the JSON files

PierreBresson commented 3 years ago

@a2br still not working at all. I think you don't really understand the task unfortunately. In the first hand, I don't see the generated files that should be comitted with all the translations. Please re-submit if you find a solution.

a2br commented 3 years ago

I have fully understood what you meant. I've been working on them this morning and their are now functional. I'll resolve some path problems and I'll open another PR this evening (with the language JSONs included then).

Note: the currently commited files indeed do not work

Update: nos working. I'll mâle them produce decent JSONs with spaces, lines, etc