Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8005137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:08:27+00:00 2026-06-04T17:08:27+00:00

I’m using default Rails i18n and have got a problem with i18ing breadcrumbs. I

  • 0

I’m using default Rails i18n and have got a problem with i18ing breadcrumbs. I use gem called “breadcrumbs_on_rails” to render breadcrumbs, so I add breadcrumbs-links in controllers like this:

add_breadcrumb I18n.t('interface.home'), :root_path

The problem is, that controller doesn’t seem to know about current locale and always uses default language.

How do I tell i18n to use selected locale, not default?

UPDATE:
Controllers know about current locale. But problem appears in strange circumstances. I used the same code in two different places in one method and found out, that i18n does not work on line 6 and works on line 10 of the following example code:

def index
  @device = Device.find_by_id(params[:device_id])
  if @device != nil
    if current_user?(User.find(@device))
      logger.debug I18n.locale # Outputs en - wrong
      add_breadcrumb t('interface.all_events'), device_events_path(@device) # Does not work
      logger.debug I18n.locale # Outputs de - correct
      add_breadcrumb @device.title, device_path(@device)
      logger.debug I18n.locale # Outputs de - correct
      add_breadcrumb t('interface.all_events'), device_events_path(@device) # Works perfect
      @events = @device.events.paginate(page: params[:page], per_page: 30)
    else
      redirect_to :root
    end
  else
    redirect_to :root
  end
end

Locale is set in application_controller.rb like was adviced in tutorial, but using http_accept_language for detection:

class ApplicationController < ActionController::Base
  protect_from_forgery
  include SessionsHelper

  def default_url_options(options={})
    I18n.locale = get_accepted_language
    { :locale => get_accepted_language }
  end

  def get_accepted_language
    available_locales = %w{en de}
    request.user_preferred_languages
    request.preferred_language_from(available_locales)
  end
end

URLs look like this: http://localhost:3000/de/devices/3/events

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:08:28+00:00Added an answer on June 4, 2026 at 5:08 pm

    Get and set the current locale:

    I18n.locale
    

    Get default locale:

    I18n.default_locale
    

    Here is all you need:
    http://guides.rubyonrails.org/i18n.html


    Try to use approach from official guides. You can set locale using before_filter:

    class ApplicationController < ActionController::Base
      protect_from_forgery
      include SessionsHelper
    
      before_filter :set_locale
    
      def set_locale
        I18n.locale = params[:locale] || I18n.default_locale
      end
    
      def default_url_options(options={})
        I18n.locale = get_accepted_language
        { :locale => get_accepted_language }
      end
    
      def get_accepted_language
        available_locales = %w{en de}
        request.user_preferred_languages
        request.preferred_language_from(available_locales)
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.