Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Remove missing translation errors

I am using internationalization for english (en) and french (fr), I have used en.yml for limited use and most of the translations I am writing in fr.yml.

With locale as fr everything works good, but with en it shows me error as missing translation span.

For eg if I have got something like

<%= text_field_tag( "search", params[:search], :placeholder=>t("Search"), :class=>"search_input") %>

and i get output for en is:

<input class="search_input" id="search" name="search" placeholder="<span class=" translation_missing"="" title="translation missing: en.Search">

What I want is that it should turn off translation errors for english, since english is my default language, but for some cases I've used en.yml.

Or if this is not possible then whole error message should be removed.

Thanks

like image 733
Paritosh Singh Avatar asked Oct 16 '12 11:10

Paritosh Singh


1 Answers

The implementation of HTML missing translation errors has been changed in Rails 4.1. Now instead of I18n library it is handled on the view helper layer. Namely, in "translate" helper method (see action_view/helpers/translation_helper.rb).

A clean way to do this now is to override the helper method and handle the exception yourself.

# app/helpers/i18n_helper.rb

module I18nHelper
  def translate(key, options={})
    super(key, options.merge(raise: true))
  rescue I18n::MissingTranslationData
    key
  end
  alias :t :translate
end
like image 188
Simon Perepelitsa Avatar answered Oct 04 '22 19:10

Simon Perepelitsa