Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preserve i18n locale on non-localized article page #379

Open
schlesingermatthias opened this issue Mar 31, 2020 · 2 comments
Open

preserve i18n locale on non-localized article page #379

schlesingermatthias opened this issue Mar 31, 2020 · 2 comments
Labels

Comments

@schlesingermatthias
Copy link

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

@schlesingermatthias schlesingermatthias changed the title i18n locale lost on non-localized article page preserve i18n locale on non-localized article page Mar 31, 2020
@jubari
Copy link

jubari commented Jul 29, 2020

@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

@github-actions github-actions bot added the Stale label Apr 11, 2024
@markets
Copy link
Member

markets commented Apr 15, 2024

ℹ️ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants