kudrykv / latex-yearly-planner

Digital planner for Supernote and ReMarkable // Support Ukraine 🇺🇦 https://savelife.in.ua/en
https://github.com/kudrykv/latex-yearly-planner/discussions
MIT License
1.11k stars 162 forks source link

Added basic translation script #106

Closed Batres3 closed 10 months ago

Batres3 commented 10 months ago

I've added a basic search and replace script (in Python) that reads the translations from a JSON file (to make it easier to modify) the default translation file is from Google Translate, it covers 133 languages, but the only one I have personally revised is Spanish. Also, there are currently issues with getting non-latin languages to work, due to Unicode and font rendering issues.

Translation takes place when TRANSLATE=[LANGUAGE] is added to the command line, [LANGUAGE] does not have to be in caps, it can be "SpAnIsH" and it would work fine, example:

PLANNER_YEAR=2022 \
PASSES=1 \
CFG="cfg/base.yaml,cfg/template_breadcrumb.yaml,cfg/sn_a5x.breadcrumb.default.yaml" \
NAME="sn_a5x.breadcrumb.default" \
TRANSLATION=SPANISH \
./single.sh
ipapast commented 10 months ago

what about making this configurable, so we can add any language we like? would you be up for that? @Batres3

Batres3 commented 10 months ago

The translation.json file is configurable, it can be changed to any language. Is this not enough? @ipapast

ipapast commented 10 months ago

The translation.json file is configurable, it can be changed to any language. Is this not enough? @ipapast

how can someone add a third language, eg german? I didn't see any option to pass a language, and thought you can only override the spanish translations in the json file, but I only skimmed the PR quickly.

Batres3 commented 10 months ago

The translation.json file is configurable, it can be changed to any language. Is this not enough? @ipapast

how can someone add a third language, eg german? I didn't see any option to pass a language, and thought you can only override the spanish translations in the json file, but I only skimmed the PR quickly.

Yes, my idea was for the Spanish translation to be overwritten to whatever the user wants

wanhoff commented 10 months ago

Maybe you could read the TRANSLATE value to specify the language. Then you could add a spanish.json, german.json, etc. This should work for a input file as it does for the output file name in single.sh line 44-46.

ipapast commented 10 months ago

Maybe you could read the TRANSLATE value to specify the language. Then you could add a spanish.json, german.json, etc. This should work for a input file as it does for the output file name in single.sh line 44-46.

yeap, that's what I was thinking more or less. make it configurable to pass any language you would like instead of overwritting the file. we could then commit more languages so that everyone can pick them up.

The translation.json file is configurable, it can be changed to any language. Is this not enough? @ipapast

how can someone add a third language, eg german? I didn't see any option to pass a language, and thought you can only override the spanish translations in the json file, but I only skimmed the PR quickly.

Yes, my idea was for the Spanish translation to be overwritten to whatever the user wants

I was thinking something like what @wanhoff suggests when I said configurable. If we pass a specific language string instead of having default as spanish, we would also be able to commit more languages in this repo. Then more people could choose what they wanted :)

Batres3 commented 10 months ago

I've added a pretty massive JSON file with 133 translations (from Google Translate, I only checked and corrected the Spanish one). It works fine, but for non-latin languages (Arabic, Chinese, Russian...) there are issues with font rendering, I've changed the command from the original pdflatex to xelatex for Unicode support, but it's still necessary to select fonts or something (I'm not very well versed in latex in non-latin languages). I've tried looking online, but most solutions use packages for specific languages, this needs to be more general (like a general Unicode font or something) @ipapast @wanhoff

kudrykv commented 10 months ago

Oof, translations are off. It's good to have a way to add them; it's best to avoid translating via translators.

kudrykv commented 10 months ago

Also it would be great if you check out rubify branch -- it's what ultimately I want to have in main.

wanhoff commented 10 months ago

Hey @Batres3, @kudrykv this looks really good to me, thanks for your great work, Batres3 and Kudrykv! Kudrykv is right, the automatic translations will not work as expected. I guess e. g. "Sun" for Sunday is translated wrong for most languages. And if possible I'd prefer a single file for every language. I think that would makes it easier to understand and maintain. I'd support the german translation.

wanhoff commented 10 months ago

Hi @Batres3 , I noticed, that "Notes" on the monthly view is not translated. I'm happy enough with to have the rest of my calendar in german, but do you have any Idea why it is still in english?

Batres3 commented 10 months ago

Hi @Batres3 , I noticed, that "Notes" on the monthly view is not translated. I'm happy enough with to have the rest of my calendar in german, but do you have any Idea why it is still in english?

It seems I completely forgot to add it, it is fixed now.

Hey @Batres3, @kudrykv this looks really good to me, thanks for your great work, Batres3 and Kudrykv! Kudrykv is right, the automatic translations will not work as expected. I guess e. g. "Sun" for Sunday is translated wrong for most languages. And if possible I'd prefer a single file for every language. I think that would makes it easier to understand and maintain. I'd support the german translation.

I've separated the big JSON into individual ones for each language, stored in translations/[language].json, some of the file names are very weird because they came for the Google Translate names for each of the languages.

Oof, translations are off. It's good to have a way to add them; it's best to avoid translating via translators.

They are indeed, I know automatic translations have lots of issues, but the only one I could manually do is Spanish (which I fixed), I just thought it'd be nice to have some samples.

Has anyone figured anything out for non-latin languages, I still can't seem to get unicode to work with xelatex.

kudrykv commented 10 months ago

the only one I could manually do is Spanish

Then Spanish only is enough. One-two languages are enough for other languages to go by analogy

Batres3 commented 10 months ago

the only one I could manually do is Spanish

Then Spanish only is enough. One-two languages are enough for other languages to go by analogy

Thats a very good point, I removed all the automatic translations, aside from Spanish and German (fixed by @wanhoff)

kudrykv commented 10 months ago

Future improvement: add English (yep-yep), use "keys" instead of raw strings. E.g., "things I'm grateful for" -> "grateful_sentence": "things I'm grateful for"