untra / polyglot

:abc: Multilingual and i18n support tool for Jekyll Blogs
https://polyglot.untra.io
MIT License
410 stars 59 forks source link

Post languages are not recognized in expected way #160

Closed Clpsplug closed 2 years ago

Clpsplug commented 2 years ago

Summary

For every page I need to be localized, I have been naming the files as follows, Japanese being the primary language for this site:

ROOT
|- index-ja.md
|- index-en.md
|- works-ja.md
|- works-en.md
|- _posts
  |- 2022-05-01-post-ja.md
  |- 2022-05-01-post-en.md

The index and works pages are localized correctly. I'm using the permalink method for these:

---
lang: ja
permalink: works
---

# "Works" page Japanese version

The posts contain the following header; notice the lack of permalink because it does not make sense:

---
layout: post
title: "Japanese post title"
date: 2022-04-24 00:00:00 +0900
lang: ja
---

# Japanese post content

The problem is that the posts are not language-filtered as I expect. Both language versions of the article are included in both language versions of the site.

This behavior is causing my language switcher to work incorrectly on my posts page.

What I expected to happen

I expect that the _site directory would look like this:

_site
|- index.html
|- works.html
|- 2022/05/01
  |- post.html
|- en
  |- index.html
  |- works.html
  |- 2022/05/01
    |- post.html

What happens instead

_site
|- index.html
|- works.html
|- 2022/05/01
  |- post-ja.html  // -ja?
  |- post-en.html  // ????
|- en
  |- index.html
  |- works.html
  |- 2022/05/01
    |- post-ja.html  // ????
    |- post-en.html  // -en?

Steps to reproduce

  1. Start a new Jekyll site
    • jekyll new PATH --blank
  2. Add the Gemfile to include polyglot
  3. Pick the language to use and define them in _config.yaml
  4. Write a post, making sure to create one for each the supported language
  5. Build a site and observe the output _site directory

Environment

Jekyll-related bundle install output is as follows:

Using jekyll 4.2.2
Using jekyll-feed 0.16.0
Using jekyll-polyglot 1.5.0

Notes

I may be understanding something in the documentation wrong, but does it happen that the 'permalink' method and the 'filename' method cannot exist beside one another?

untra commented 2 years ago

Hello @Clpsplug 👋

If you don't specify permalinks, then polyglot tries it's best to associate posts by file path. Make sure your posts have the lang specified (but you do say you have that). Jekyll will parse the date from the filename, but not the language suffix from the file.

If you look at these example files and how they're structured:

https://github.com/untra/polyglot/tree/master/site%2F_posts

That should generate a site directory like so, which I believe is what you're aiming for:

https://github.com/untra/polyglot/tree/master/site/_site

Specify posts under language folders, instead of with a language suffix.

Clpsplug commented 2 years ago

Hello @untra! Yep, that was it. Seems like I misunderstood the "tries its best to associate posts by file path" part. I thought it can associate posts using literally any part of the path. Using the language directory fixed the problem! Thanks for the help!