kurtsson / jekyll-multiple-languages-plugin

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

Translate collections #72

Open rdoylespk opened 8 years ago

rdoylespk commented 8 years ago

Hi!

Is it possible to translate collections? Right now, I have to manage 2 separates collections and I've created a tag to link the posts together. It's working but I've got to do a lot of validation to make it work and it's not reusable if wI need to use it in another project.

Thanks!

Anthony-Gaudino commented 8 years ago

Hi @rdoylespk,

unfortunately it's not possible right now, so this would need to be implemented.

andrewhilts commented 7 years ago

FWIW I got translated collections to work in an inelegant way, but it works for my use case.

Let's say I have two languages, en and zh. I have a post in both _i18ln/en and _i18ln/zh in which I want to embed links to the docs in my resources collection.

My config.yml has this in it:

collections:
  resources:
    output: true
    permalink: /resources/:path/

I have a folder called _resources in my root directory, with this folder structure.

├── en
│   └── test.html
│   └── test2.html
└── zh
    └── test.html
    └── test2.html

test.html looks like this in the en folder:

---
title: "Test 1"
---
Test 1 Content

test.html looks like this in the zh folder:

---
title: "測試1"
---
測試1個內容

test2.html follows the same pattern in each folder.

In my posts for en and zh, If I want to present links to the pages in my resources collection, I can do the following:

{% for resource in site.resources %}
    {% assign resource_lang = resource.url | slice: 11, 2 %}
    {% if resource_lang == site.lang %}
      <a href="{{resource.url}}">{{resource.title}}</a>
    {% endif %}
{% endfor %}

This creates links to docs in the resources collection, but only if the doc url contains the site.lang string at index 11 (after /resources/).

The above will output this in the en post: <a href="/resources/en/test1.html>Test1</a> <a href="/resources/en/test2.html>Test2</a>

The above will output this in the zh post: <a href="/resources/zh/test1.html>測試1</a> <a href="/resources/zh/test2.html>測試2</a>

The items will be ordered alphabetically. There's probably a way to order them by some YAML front matter attribute present in each collection doc, as well, with some extra Liquid magic

I hope this helps some people!

SeeTwoDev commented 7 years ago

Can you, somehow, translate content and then pass it to a layout?

I can't seem to find how.