untra / polyglot

:abc: Multilingual and i18n support tool for Jekyll Blogs
https://polyglot.untra.io
MIT License
410 stars 59 forks source link

Fallback in _data ymls #138

Closed victorbnl closed 3 years ago

victorbnl commented 3 years ago

I have this

_data
├── en
│   └── strings.yml
└── fr
    └── strings.yml

Actual behaviour

And at some point of my site I use one of the strings in th yml, works fine on french and english but in spanish pages it works fine but on the spanish page there is nothing.

Expected behaviour

It should see there is no spanish "strings" and use the default_language's one, so english, and display an english string on the spanish page

untra commented 3 years ago

Heya @victorbnl 👋

so truth be told polyglot isn't going to relativize or fallback for content in those _data directory files. Long ago I actually wrote some wiki words about the difference between Basic Content (whole pages and posts, which is what Polyglot mostly helps manage) and Rich Content (things like small strings and specific resources for a language, like what goes in the .yml files)

An easy workaround is to just copy the en/strings.yml as is and use that for your spanish es/strings.yml . Thats your rich text, and those small strings are worth getting 100% translated right away for your spanish site. blog posts and pages are a lot of work to translate, and thats worth having a default language (english) fallback for. IMHO this is not the case for small strings.

Hopefully this makes sense.

victorbnl commented 3 years ago

Well it's not the case. If we must copy the english file to spanish folder everytime we add a string in the english file that's not a viable solution at all. My site is not that big but imagine having more than 100 or 1000 strings, that very quickly becomes a nightmare. But I understand if you don't want to implement it and if polyglot isn't made for that so as you want, I'll keep looking for another solution then.

Thanks a lot for your answer!

victorbnl commented 3 years ago

I tried reading the code and understanding it a bit in order to make a pull request but I struggle a lot. Anyway if I succeed in understanding the code and writing a pull request who works doing it would you accept it?

untra commented 3 years ago

I have absolutely accepted pull requests from other contributors to Polyglot for quick fixes and other improvements. However...

This is actually a harder problem than it looks, with a lot of edge cases around different shapes of .yml file data, and any solution you come up with that updates polyglot core library code will also need tests written as well.

I just want to reiterate: rich text strings in the .yml files used for translations are best kept in-sync rather than fallen back on. if you have a lot of small strings used this way throughout the application for each language you support, adding another language can be easily accommodated by just copying the default language strings and then updating them for the language as needed. Those rich text strings are meant to be short and finite, useful for menu navigation or callouts.

imho this is a lot of work for little reward but if you're ambitious go for it.

victorbnl commented 3 years ago

Then I'm not going to try to write a pull request for that.

But I still think it would be very useful because _data's goal is to simplify adding quickly things without necessarly going in other files etc. Also copying the string to the other languages goes against the Don't Repeat Yourself principle. Also it becomes not only complicated if you have a lot of strings, but also just for languages. If you want to add a little link in the sidebar and your site is translated in 100 languages you have 99 useless copy/paste to do (well I exagerate, but this can be very annoying even with way less languages).

However I understand that this is a lot of work and that not everyone would use it so I understand your decision.

Thanks for your answer, good luck for your projects!