untra / polyglot

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

sample.md defines its language as site.data["active_lang"] but this may cause errors... #182

Closed antoniovazquezblanco closed 8 months ago

antoniovazquezblanco commented 9 months ago

It turns out that if you print the lang variable at lib/jekyll/polyglot/patches/jekyll/site.rb in the function coordinate_documents the variable has not been evaluated in a context thus resulting in having the site.data["active_lang"] as a valid value...

This can cause problems if data is not defined for a single language...

The value of lang should be evaluated in context or lang may be changed to allow it to be a vector of valid langs...

This is preventing me from creating a liquid tag that can fetch file urls for different translations...

antoniovazquezblanco commented 9 months ago

See https://github.com/antoniovazquezblanco/polyglot/tree/dev/linklang for the implementation of the liquid tag I am trying to create...

Thanks!

untra commented 9 months ago

I'm making some improvements for running rspec tests in ci. https://github.com/untra/polyglot/compare/master...antoniovazquezblanco:polyglot:dev/linklang#diff-4ba1e609c8b3d54fb7d83205ca7c2e807fe0bd93052f7ecd2ded36d49fdbe1e6R135-R140 your changes in site.rb seem necessary and make sense. If you can add more tests I'll feel better about getting changes out.

If you want to also contribute the LinkLang tag that would also be cool

antoniovazquezblanco commented 8 months ago

Your latest changes crush it man!

I am thinking on contributing the linklang tag in order to provide linking without redirection but the current approach suits my needs! Also, your recent changes allow me to implement the linklang tag in a more elegant way :D

Thanks!

untra commented 8 months ago

😁 Hell yeah, thanks again for your help @antoniovazquezblanco !

I changed the lang_id to page_id because it seemed to reduce visual confusion in the frontmatter and code.

The jekyll-redirect-from gem was something I had to recently study for work and I saw the complete implementation and goal. Different permalinks make language switching challenging, but automatically coordinating the redirects for corresponding pages is easily solvable.

The flexibility of that plugin to customize the redirect.html with polyglot conventions makes it all just work.

Thanks for your patience while I prepped the approach and release 👍

antoniovazquezblanco commented 8 months ago

A new approach on how to implement the functionality I seek is proposed in https://github.com/untra/polyglot/pull/185.

This issue can be closed :)