middleman / middleman-blog

Blog Engine Extension for Middleman
https://middlemanapp.com
MIT License
326 stars 179 forks source link

preserve i18n locale on non-localized article page #379

Open schlesingermatthias opened 4 years ago

schlesingermatthias commented 4 years ago

Hi, I'm having trouble getting localization to work with middleman-blog. I have a localized webpage where all pages are localized using the t() helper. I don't want to translate blog posts that's why the articles themselves are not localized. This works pretty well except that the currently used locale is lost on the non-localized article page.

On my localized blog overview page (/en/blog or /de/blog) everything works well. <%= I18n.locale %> prints en or de respectively. The articles on this page link to not localized article pages (blog/2020/03/31/my-article.html). Inside my article layout <%= I18n.locale %> always prints en even if I arrived at the page from de/blog.

Is there a way to preserve the locale on the article page?

My config:

activate :blog do |blog|
  blog.layout = "blog_layout"
  blog.permalink = "blog/:title.html"
  blog.sources = "articles/:title.html"
  blog.preserve_locale = true
end

Or another non-hacky way to use multiple locales with a single article source directory? I tried using multiple blog configs for each language but this does not work with only one source directory and I don't want to duplicate articles for every locale.

Thank you

jubari commented 4 years ago

@schlesingermatthias Did you find a solution for this problem? We are running to the exact same scenario.

Found a solution 5 minutes later: Seems very counter-intuitive but setting blog.preserve_locale = false actually solved the problem. Article page now correctly recognizes /de/blog/foobar as I18n.locale == :de

markets commented 6 months ago

ℹ️ This issue is stale because it has been open for more than 90 days with no activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.