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

How to put the default language in a subfolder? #86

Open
klaasnotfound opened this Issue Jan 27, 2017 · 6 comments

Comments

Projects
None yet
5 participants
@klaasnotfound

klaasnotfound commented Jan 27, 2017

This is a fantastic plugin - thank you so much for creating it!

One thing that I was unable to figure out is how to configure the plugin so that all the languages (including the default language) end up in a subfolder.
Suppose I have languages ["en", "de"]. English is the default and put into the root folder. However, for consistency I would like to have the English content in the subfolder en/, just like the German content, which resides in de/.

Is this possible?

@efkawu

This comment has been minimized.

efkawu commented Jan 27, 2017

Good question, I have got the same issue.

@klaasnotfound

This comment has been minimized.

klaasnotfound commented Jan 30, 2017

Since the plugin doesn't seem to support this, I have hacked together a basic solution. I had to learn some Ruby (and the basics of Jekyll plugins) first, so it's probably not the prettiest approach. But it's working.

To use it, you need to install the plugin manually. If you were using the installed version of the plugin before, be sure to remove the old plugin gems entry from your _config.yml, otherwise you're invoking two versions of the plugin and will see errors. Then replace the jekyll-multiple-languages-plugin.rb in the lib folder with this code.

The modified version does three things:

  • The default language (the first one in the languages array) is now put into a subfolder, just like the other languages. The script respects the exclude_from_localizations entry and puts these assets into the root folder of your _site.
  • Because all the languages now reside in their own subfolder there is no central index.html, which is a bit inconvenient. The script therefore (by convention) looks for a file called base.html in the root folder of your project. If that file exists, it becomes the new index.html of your _site. You can use base.html to do detect the browser language and redirect the user to the right subfolder. I have provided a minimal working example here.
  • I also needed to use custom collections. The original plugin currently doesn't support translating permalinks and namespace links for collection documents (see other issue), so I fixed this.

In a nutshell, when using the modified plugin you should be able to run jekyll build on a multilingual site with custom collections and end up with a properly built _site that has each language in its own subfolder, an index.html that does redirects (provided you have a base.html file) and the ability to use the {% tl ... %} and {% tf ... %} tags with correctly localized permalinks.

Note: The modified plugin is currently incompatible with the original (I had to remove and alter some code that relied on the default language being in the root folder), which is why I didn't crate a pull request. As of now, I don't have the time and/or Ruby/Jekyll expertise to reconcile the two approaches, but I'm hoping some of the more experienced contributors can pick it up from here. A basic flag in the _config.yml (e.g. default_lang_in_root_folder) could indicate whether to use one solution or the other.

@Etua

This comment has been minimized.

Etua commented May 29, 2017

Definitely in need of out of the box solution. I'd like to use this feature however I don't want to mess with configuring gems manually.

@Paludis

This comment has been minimized.

Paludis commented Jun 28, 2017

Same issue here. For consistency I want all languages in their own subfolder.

@aumars

This comment has been minimized.

aumars commented Jul 17, 2017

@klaasnotfound I panicked when I found out that the plugin couldn't support GitHub Pages, you saved me! You should continue fixing the issue and maybe make a pull request.

@klaasnotfound

This comment has been minimized.

klaasnotfound commented Jul 31, 2017

@aumars Yeah, that would be the right thing to do... Unfortunately I currently don't have the time or Ruby skills to work on it.

I forgot to mention that I wrote a small blog post on how to use the modified plugin:
http://www.klaasnotfound.com/2017/02/16/proper-multilingual-site-with-github-pages-and-jekyll/

It provides a bit more detail on how to set up a new site and what to watch out for when using GitHub Pages and i18n.

bpatra added a commit to Talentoday/jekyll-multiple-languages-plugin that referenced this issue May 24, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment