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 7050147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:06:29+00:00 2026-05-28T03:06:29+00:00

I am using Ruby on Rails 3.1.1 and I am trying to translate email

  • 0

I am using Ruby on Rails 3.1.1 and I am trying to translate email messages body. I created/stated all necessary “things” (YAML files, key/value pairs, …) to make the I18n gem to work: email messages are sent without problems using the default language (:en).

Then I added a new language and made all that had to be done to make the I18n gem to work with another language and to get always a locale=de parameter in URLs.

class ApplicationController < ActionController::Base
  before_filter :set_locale

  def set_locale
    if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym)
      I18n.locale = params[:locale]
    end
  end

  ...
end

However when I sent an email, even if the locale is properly set (eg: locale=de), sent email message are not translated (those still use the default :en language).

How can I make the I18n to translate email messages body?


  • I read the Localized ActionMailer Templates for Rails blog post
    but it is old and I have not tested that…
  • I read the Rails I18n and emails blog post and I tested that. It works, but how can handle translation in my case (I am using the params method…)? Is there a better solution?
  • 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-05-28T03:06:29+00:00Added an answer on May 28, 2026 at 3:06 am

    Solution

    In your railsproject make a mailer (read http://guides.rubyonrails.org/action_mailer_basics.html how to make one). For example UserMailer.

    rails g mailer UserMailer
    

    Define a method for example mail_user.

    def mail_user(user)
        @user = user
        mail(:to => "test example <testuser@testuser.com>", :subject => "hello")
    end
    

    Now define views. For example: mail_user.de.html.erb and mail_user.en.html.erb. Put your translations in there. If you want to translate variables seperatly use:

    <%= I18n.t("foo.bar") %>
    

    When you do this, ensure you have a en.yml and de.yml translation! Define a translation like the following example:

    foo:
        bar: hello
    

    You should be ready to go.

    How this works

    ActionMailer works the following way. You can create mailer models which inherit from ActionMailer::Base. Like ActionController the models have associated views (templates) in the /app/views/ directory.

    Now here is the technical part and why this all magicly works. ActionController and ActionMailer default include AbstractController::Rendering directly or indirectly (ActionController::Metal::Rendering). AbstractController::Rendering uses ActionView as default library for its template rendering engine and includes AbstractController::ViewPaths and an instance of I18n proxy to find localized views. To learn more i’d like to refer to the ActionPack source code on github.

    To get to the point. ActionView allows you to use localisation in your templates: See Rails guide: Action View Overview , Chapter Localized views.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to send email with attachments using Ruby on Rails. I followed
I'm trying to write an app using Ruby on Rails and I'm trying to
I'm trying to build a web service using Ruby on Rails. Users authenticate themselves
using Ruby on Rails 2.3.2, since I already created Scaffold for Story, so instead
I'm using Ruby on Rails with jQuery and trying to do the following: <%=
I have created a blog application using Ruby on Rails and have just added
I am trying to build a free web application using ruby/rails It should be
I was trying to switch the layout using Ruby on Rails but I am
I am trying to set up Ruby on Rails on windows. I am using
I am trying to make a auto complete box using ruby on rails, jquery

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.