Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hacketiwack opened this issue May 3, 2024 · 3 comments
Open

Comments

@hacketiwack
Copy link
Contributor

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

  • /en/my-post/
  • /fr/mon-article/
  • /de/mein-blogartikel/

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
Copy link
Owner

untra commented May 3, 2024

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
Copy link
Contributor Author

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
Copy link
Contributor

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.

hacketiwack added a commit to hacketiwack/polyglot that referenced this issue May 4, 2024
It ensures that the permalink_lang attribute is set correctly and can be used when a permalink attribute is set at the site level.
It is, indeed, not enough to check if the permalink is undefined. The permalink might be set to empty. Moreover, we should check that the page has a lang attribute isn't empty as well.
untra pushed a commit that referenced this issue Aug 16, 2024
It ensures that the permalink_lang attribute is set correctly and can be used when a permalink attribute is set at the site level.
It is, indeed, not enough to check if the permalink is undefined. The permalink might be set to empty. Moreover, we should check that the page has a lang attribute isn't empty as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants