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

Apache Content Negotiation and Eleventy #761

Closed
rachelandrew opened this issue Nov 4, 2019 · 5 comments
Closed

Apache Content Negotiation and Eleventy #761

rachelandrew opened this issue Nov 4, 2019 · 5 comments
Labels
education feature: 🗺 i18n Internationalization and localization of Eleventy projects

Comments

@rachelandrew
Copy link

There is a method of internationalizing content which uses Apache Content Negotiation - explained in this post.

To do this you need to name your files with a language code eg about/history.en.html, about/history.fr.html and then linking to about/history uses a rewrite to return the version for the language of the user.

I am working on a site where they wish to use this method and I really want to use Eleventy. I can use the overrides in Eleventy to create the named files, but then this makes actually working with the site in development impossible, as all my links go to the bare main file name (e.g. about/history) and there is no way to go to the internationalized versions.

If anyone has any ideas as to how I can get this working I would be very grateful. I'm aware there are other ways of doing internationalization, I'm interested as to whether this one is possible.

@Ryuno-Ki
Copy link
Contributor

Ryuno-Ki commented Nov 4, 2019

Related to #243 and #420: We should keep this use case in mind when tackling i18n.

@adamduncan
Copy link

adamduncan commented Jun 6, 2020

Hey @rachelandrew, really interesting approach!

I've made up a proof-of-concept repo (eleventy-l10n-demo), which includes the files/config to support the approach explained in the post you referenced.

We can get creative with Eleventy's permalink, and how we author and output .htaccess files (either manually or by generating from a data file). That should result in us having the LANGCODE.html suffixes we're after in the site output. Some nice ideas out there around maintaining relative links in Eleventy sites, too!

This demo site leverages Netlify's redirects to achieve the same as what we'd configure with .htaccess in Apache (see demo's netlify.toml):

https://eleventy-l10n-demo.netlify.app/
https://eleventy-l10n-demo.netlify.app/about

To test, Quick Accept-Language Switcher is handy for ensuring the language settings are being honoured (en, ja and es in this case).

I hope that helps you or someone else exploring this approach. Definitely one to keep in mind as an alternative to a more manual i18n approach. Thanks for highlighting it! 👍

@zachleat zachleat added the feature: 🗺 i18n Internationalization and localization of Eleventy projects label Jul 1, 2022
zachleat added a commit to 11ty/11ty-website that referenced this issue Jul 1, 2022
zachleat added a commit that referenced this issue Jul 1, 2022
@zachleat
Copy link
Member

zachleat commented Jul 1, 2022

Sorry I’m so late to this party but I was able to dig into this today and made a few changes as a result.

For this style of approach I do think it’s better to swap your default permalink behavior to use .html instead of index.html for everything, so I’d start there:

https://www.11ty.dev/docs/data-eleventy-supplied/#changing-your-project-default-permalinks

The new stuff I added for this use case specifically is available on the docs here: https://www.11ty.dev/docs/permalinks/#mapping-one-url-to-multiple-files-for-internationalization

I think this will clean up the example you linked to a bit @adamduncan in that you don’t need to hardcode permalinks throughout your files and you will be able to use page.url (et al) as expected without other changes.

I’m at close of business today but I’m curious to hear y’alls thoughts!

@zachleat zachleat added this to the Eleventy 2.0.0 milestone Jul 1, 2022
@zachleat
Copy link
Member

This is now officially discussed on our new i18n docs page https://www.11ty.dev/docs/i18n/ though we really recommend the folder based approach for file organization but both will work!

@fromjasonstuff
Copy link

@zachleat sorry if this isn't the place to ask, still getting use to github. I was wondering why the folder approach is recommended for file organization over an extensionless url like described in this article. I'm trying to decide what is best and honestly have no idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
education feature: 🗺 i18n Internationalization and localization of Eleventy projects
Projects
None yet
Development

No branches or pull requests

5 participants