user938363
user938363

Reputation: 10378

RAILS: How to eliminate `translation missing` from some I18n.t in production (I18n.t fallback enabled)?

In my Rails 4.2 app, all modules are developed with I18n.t(). Here is an example of the index.html.erb:

<table class="table table-hover">
  <thead>    
    <tr>
      <th><%= t('Create Date') %></th>
      <th><%= t(@for_which.sub('_', ' ').titleize) %></th>
      <th><%= t('Brief Note') %></th>
      <th><%= t('Ranking Index') %></th>
      <th><%= t('Active') %></th>
      <th><%= t('Entered By') %></th>
      <th></th>
      <th></th>
    </tr>
     </thead>
       <tbody>

In local.rb under initializers, local is set to en:

I18n.enforce_available_locales = false
I18n.default_locale = 'en' if Rails.env.production? || Rails.env.development?
I18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]

But I still see error of translation missing from some of the I18n.t in both production and development, such as tab and index title as below: enter image description here

How do I get rid of error of translation missing?

UPDATE: The error translation missing shows up in production even with the following I18n.t fallback in environment/production.rb:

 # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation cannot be found).
  config.i18n.fallbacks = true

UPDATE: Added CSS:

//hide all "translation missing" warnings:
body.production span.translation_missing {
  display: none;
}

But words on tab, buttons, and table header disappear: enter image description here

Here is portion of html source showing for one of the tab Employee Infos:

            <li class="dropdown">
        <a id="dropdownuser" href="#" data-toggle="dropdown" class="dropdown-toggle" data-toggle="tooltip" data-placement="bottom" ><span class="glyphicons glyphicons-yen text-danger"></span> <span class="translation_missing" title="translation missing: en.Employee Info">Employee Info</span> <b class="caret" id="caret_medium"></b></a>
              <ul id="banktransaction" class="dropdown-menu" role="menu">

                <li><a href="/tt/view_handler?index=1&amp;url=/tt/tsheet/employee_infos"><i class='glyphicon glyphicon-list'></i> translation missing: en.List</a></li>
                <li></li>
                <li><a href="/tt/view_handler?index=1&amp;url=/tt/tsheet/employee_infos/search"><i class='glyphicon glyphicon-list-alt'></i> translation missing: en.Search</a></li>                
              </ul>
            </li>

Upvotes: 3

Views: 6651

Answers (3)

Kasia Ekiert
Kasia Ekiert

Reputation: 52

Use 'Faker::Job' instead of 'Name.title '

Faker::Job
Faker::Job.title #=> "Lead Accounting Associate"

Faker::Job.field #=> "Manufacturing"

Faker::Job.seniority #=> "Lead"

Faker::Job.position #=> "Supervisor"

Faker::Job.key_skill #=> "Teamwork"

Faker::Job.employment_type #=> "Full-time"

Faker::Job.education_level #=> "Bachelor"

It works for me :)

Upvotes: 0

Kaka Ruto
Kaka Ruto

Reputation: 5145

I have no idea why, but I just restarted my server and boom! It worked.

You can try restarting your server too :)

Upvotes: 0

MZaragoza
MZaragoza

Reputation: 10111

in your #config/application.rb file you can do something like this

Rails.application.configure do |config|
  config.action_view.raise_on_missing_translations = false
end

you can get more here

I hope that this is able to help you :)

Upvotes: 4

Related Questions