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

What is the better way to handle locales? #298

Open
pil0u opened this issue Apr 21, 2024 · 0 comments
Open

What is the better way to handle locales? #298

pil0u opened this issue Apr 21, 2024 · 0 comments

Comments

@pil0u
Copy link

pil0u commented Apr 21, 2024

Hello,

I have been successfully using meta-tags to handle i18n in the sense that for a given page, my application controller knows the locale and displays it in the right language. So are my meta tags.

Here is a simple example of my PagesController:

class PagesController < ApplicationController
  def home
    set_meta_tags(
      title: _("Home"),
      description: _("This is my Home description."),
      image_src: request.base_url + ActionController::Base.helpers.image_path(_("og_image_en.png")),
      index: true,
      og: {
        type: "website",
        url: request.original_url,
        title: _("My website"),
        description: _("This is my Home description."),
        image: request.base_url + ActionController::Base.helpers.image_path(_("og_image_en.png"))
      }
    )
  end
end

My home page is routed via /, but also, I handle my locales via the URL this way: https://mydomain.com/fr. Here is how my router works:

Rails.application.routes.draw do
  scope "(/:locale)", locale: /#{I18n.available_locales.join('|')}/ do
    root to: "pages#home"
  end
end
  • meta tags work well in all languages for https://mydomain.com/
  • they don't work for https://mydomain.com/:locale, even if that is the same page

Any recommendation would help, thank you!

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

No branches or pull requests

1 participant