Closed davrandom closed 10 years ago
Hi @davrandom
Thank you for your feedback, I'm aware that the documentation can be much better and Im happy to get some help. If you are willing to create a minimal multilingual website I will happily merge it in to the main branch.
The answer to you specific question however I can answer:
{% if site.lang == "sv" %}
{% capture link1 %}{{ site.baseurl_root }}/en{{ page.url}}{% endcapture %}
<a href="{{ link1 }}" >{% t global.english %}</a>
{% else if site.lang == "en" %}
{% capture link2 %}{{ site.baseurl_root }}{{ page.url }}{% endcapture %}
<a href="{{ link2 }}" >{% t global.swedish %}</a>
{% endif %}
This snippet will create a link that will toggle between Swedish and English. The interesting variables are:
Name | Value | Example |
---|---|---|
site.lang | The language used in the current compilation stage | en |
site.baseurl | Points to the root of the site including the current language | http://foo.bar/en |
site.baseurl_root | Points to the root of the page without the language path | http://foo.bar |
page.url | The current page's relative URL to the baseurl | /a/sub/folder/page/ |
There you have it, I will merge this in to the main readme, please tell me if you have any other problems.
Can I close this issue?
Thanks for replying so quickly! I definitely can produce a minimal website to illustrate how the plugin works, as soon as I have something working. I don't understand what should be my approach to have your code working. Tell me if I'm wrong (and I am for sure): 1 - the name of the post for different languages should be the same but placed in different folders, e.g.
_posts -> main language, _posts/2013-12-26-example.md
_posts/en -> posts in english, _posts/en/2013-12-26-example.md
_posts/es -> posts in spanish, _posts/es/2013-12-26-example.md
etc...
2 - I should use a header like:
layout: post
title: Esempio
date: 2013-12-26 12:00:00
lang: it
categories: it posts
for italian,
layout: post
title: Example
date: 2013-12-26 12:00:00
lang: en
categories: en posts
for english, etc. The resulting pages are, for example: http://davrandom.github.io/it/posts/2013/12/09/example-post.html http://davrandom.github.io/en/posts/2013/12/09/example-post.html Is this a valid result?
3 - Where should I put something like your snippet code? (The structure of jekyll is not exactly clear to me yet)
Thanks for your help d
Ok now I understand your problem a bit more.
The plugin does not handle translated posts (even though this would be a nice addition and probably quite easy to add) but aims for you not have to duplicate your layouts and includes. I would use the category feature in Jekyll to be able to separate the different languages in the posts.
Like this:
_posts -> main language, _posts/2013-12-26-example.md
_posts/en -> posts in english, _posts/2013-12-26-example-en.md
_posts/es -> posts in spanish, _posts/2013-12-26-example-es.md
etc...
2 - I should use a header like:
layout: post
title: Esempio
date: 2013-12-26 12:00:00
categories: it posts
for italian,
layout: post
title: Example
date: 2013-12-26 12:00:00
categories: en posts
for english, etc.
The resulting pages are, for example: http://davrandom.github.io/posts/2013/12/09/example-post.html http://davrandom.github.io/it/posts/2013/12/09/example-post.html http://davrandom.github.io/en/posts/2013/12/09/example-post.html
This is possible and you can create links that goes from one post to another with the same name in the layout files using the snippet I posted before.
Can you write a second issue about the missing post feature and explain how you want it to work?
You can add this completely untested monkey patch to the multiple languages and it should probably pick up the language folder in the posts directory:
def read_posts(dir)
posts = read_things(dir, '_posts/#{self.config['lang']}', Post)
posts.each do |post|
if post.published && (self.future || post.date <= self.time)
aggregate_post_info(post)
end
end
end
Paste the snippet just before
end
class LocalizeInclude < Jekyll::Tags::IncludeTag
Please tell me if it worked @davrandom
So, for what concerns the part related to this plugin, if I follow what you suggested and I add in my _layouts/posts.html you snippet code I get a:
The tag t
in _layouts/post.html
is not a recognized Liquid tag.
from github pages.
In my local site it doesn't work anyway. (I'll open another issue for the post translation) Thanks d
Check out my commit https://github.com/screeninteraction/davrandom.github.io/commit/bbe2f57a1712496570676928f8f875419a29ac42 for an example of a translated string
Hi, I'm very new to jekyll (at the moment I'm working locally, migrating my textpattern website to jekyll). I would really love to be able to manage multiple languages (it, en, es). The problem that I'm facing is that for a jekyll-newbie your readme is a bit too short. In particular -imho- is lacking some friendliness in the "usage" side. I cannot figure out how to link two posts that are the translated versions of the same post. Maybe a minimal multilingual example website could help.
I hope I'm not alone :D Thanks for your time d