kurtsson / jekyll-multiple-languages-plugin

I18n support for Jekyll and Octopress
MIT License
925 stars 202 forks source link

translate and loops #66

Closed buraktamturk closed 8 years ago

buraktamturk commented 8 years ago

Hello,

I can't use the translate tag with for loops. Is it supported?

my en.yml file

symbols:
  - title: First
    message: Message
  - title: Second
    message: Message
{% for a in translate symbols %}
        <li>
            <h2>{{ a.title }}</h2>
            <p>{{ a.message }}</p>
        </li>
{% endfor %}
Anthony-Gaudino commented 8 years ago

Hi @buraktamturk, sorry for taking so long to answer you.

I released version 1.4.2 with a small patch that allows you to access the site.translations hash. This way you can use it in a Liquid for loop like this:

{% for item in site.translations[site.lang]["my_nested_yaml_collection"] %}
    <p>{{ item[0] }} -> {{ item[1] }}</p>
{% endfor %}

For the following YAML:

symbols:
  -
    title: First
    message: Message
  -
    title: Second
    message: Message

The following code should work:

{% for item in site.translations[site.lang]["symbols"] %}
   <li>
      <h2>{{ item["title"] }}</h2>
      <p>{{ item["message" }}</p>
   </li>
{% endfor %}

If you find any trouble please feel free to comment bellow.

buraktamturk commented 8 years ago

Hello, thanks for the work! I think it'll fit perfectly to my use case, and I'll test whenever possible soon.