Rails: Remove missing translation errors

2019-02-08 10:20发布

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

7条回答
冷血范
2楼-- · 2019-02-08 11:07

In Rails 4.1, I wasn't able to get this to work with the I18n exception handler (there are some bugs, apparently, see nathanvda's answer.
Eventually I just overwrote the message function by adding this to config/initializers/i18n.rb

module I18n
  class MissingTranslation
    module Base
      def message
        keys[1..-1].join('.')
      end
    end
  end
end
查看更多
登录 后发表回答