title: Rails 5 I18n default_locale and fallback locale
body: <p>How do I set a fallback locale in Rails 5.2?</p>
  
  <p>Right now it prints ''(blank) for attribute names if not found in locale. I would like it to fallback to :en when that happens. </p>
  
  <p>Rails 5 specific?</p>
  
  <pre><code># config/application.rb 
  config.load_defaults 5.0
  config.i18n.default_locale = :nb
  </code></pre>
  
  <p>run specs and get:</p>
  
  <pre><code>#&lt;ActiveRecord::RecordInvalid: Det oppstod en feil: er allerede i bruk&gt;
  see the missing part here:
  #&lt;ActiveRecord::RecordInvalid: Det oppstod en feil: [MISSING RECORD NAME] er allerede i bruk&gt;
  
  # switch to 
  # config.i18n.default_locale = :en
  #&lt;ActiveRecord::RecordInvalid: Validation failed: Report date has already been taken&gt; 
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>@Nate got the fallback config correct in his answer below (<a href="https://stackoverflow.com/a/53453211/252799">https://stackoverflow.com/a/53453211/252799</a>) </p>
  
  <p>That wasn't the issue though. The problem, I learned, was in my <code>nb.yml</code>. </p>
  
  <ul>
  <li><em>Experiment 1.</em>
  Deleting the entire content of nb.yml, leaving just hello world. <em>Works</em>: It prints the attribute (associated record) name.</li>
  <li><em>Experiment 2.</em> 
  Replacing our nb.yml with the official Rails nb.yml: <a href="https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/nb.yml" rel="nofollow noreferrer">https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/nb.yml</a> :  <em>Works</em>. I get the helpful norwegian-english message <code>Det oppstod feil: Company må eksistere</code>. Not pretty, but helpful and what I wanted!</li>
  <li><em>Experiment 3.</em> Proof. The nb.yml reproduces the problem.</li>
  </ul>
  
  <p>Two approaches</p>
  
  <pre><code># A: SHOW attribute name
  nb: 
    errors:
      format: "%{attribute} %{message}"
  
  # B: HIDE attribute name
  nb:
    errors:
      format: "%{message}"
  </code></pre>
  
  <p>Which leads to another problem. </p>
  
  <p>Approach <strong>B: HIDE</strong> makes you blind serverside. the specs, logs and console will show <code>Validation Failed: can't be blank</code> but it looks good in UI.</p>
  
  <p>I posted another Q: <a href="https://stackoverflow.com/questions/53500734/simpleform-errors-without-attribute-name-but-using-attribute-name-in-logs-cons">Simpleform errors without attribute name, but using attribute name in logs, console, specs</a></p>