untra / polyglot

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

Ability to get a page URL in another language when page_id is used #199

Open hacketiwack opened 6 months ago

hacketiwack commented 6 months ago

Context I want to be able to have different URLs for posts in different languages. e.g:

Today, this is possible to do it thanks to the page_id in the front matter of the post. However, for this to work, you'll need to specify a permalink for each post, which is quite annoying. Why? Because, if you can easily forget to enter this attribute and then switching from one language to another won't work. In Jekyll, you can add a default permalink attribute for all the pages. However, this doesn't seem to be taken into account by polyglot. Thus accessing the permalink through permalink_lang[lang] doesn't work.

Experiments What I tried so far, was to create a language selector that would retrieve all the site.posts and site.pages. Why? Because, I wanted to access the url attribute of a post/page in another language. However, these are already filtered out by polyglot before I access them. Thus it's impossible to get this url attribute. This is confirmed by these issues: 186, 53, 88.

Ideas Reading issue 186, it seems there is no will to implement it. However, is there any other way to get these URLs? Would it be possible to implement an attribute url_lang similar to the permalink_lang?

Thanks for any advice.

untra commented 6 months ago

Have you seen these examples?

these use the jekyll-redirect gem and a custom redirect layout to accomplish both custom permalinks and sane language switcher on pages. https://github.com/untra/polyglot/blob/master/site/_layouts/redirect.html

yeah those examples are pages, not posts. But that shouldn't matter necessarily.

hacketiwack commented 6 months ago

Thanks for the examples. However, these examples all make usage of the permalink in the front matter. Which I'd like to avoid, because it would mean that that the author of each page/post would have to give a permalink manually. I would prefer to have the permalink defined as '/:title/' in _config.yml to be taken into account by polyglot. I hope I was clear enough with my explanation.

george-gca commented 6 months ago

Maybe you can create a generator plugin for your specific case? Then you can try to make it run before polyglot by setting its priority.