Skip to content

What is the better way to handle locales? #298

@pil0u

Description

@pil0u

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions