Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Important</strong>: Make sure your app is not using I18n 0.6.8, it has a <a href="https://github.com/svenfuchs/i18n/commit/2893ebf4674a12fcded5779ad13fa05dc74dbf5e" rel="noreferrer">bug that prevents the configuration to be set correctly</a>.</p> <hr> <h2>Short answer</h2> <p>In order to silence the warning edit the application.rb file and include the following line inside the <code>Rails::Application</code> body</p> <pre><code>config.i18n.enforce_available_locales = true </code></pre> <p>The possible values are:</p> <ul> <li><strong>false</strong>: if you <ul> <li>want to skip the locale validation</li> <li>don't care about locales</li> </ul></li> <li><strong>true</strong>: if you <ul> <li>want the application to raise an error if an invalid locale is passed (or)</li> <li>want to default to the new Rails behaviors (or)</li> <li>care about locale validation</li> </ul></li> </ul> <p>Note:</p> <ul> <li>The old default behavior corresponds to <code>false</code>, not <code>true</code>.</li> <li>If you are setting the <code>config.i18n.default_locale</code> configuration or other i18n settings, make sure to do it after setting the <code>config.i18n.enforce_available_locales</code> setting.</li> <li>If your use third party gems that include I18n features, setting the variable through the Application <code>config</code> object, may not have an effect. In this case, set it directly to <code>I18n</code> using <code>I18n.config.enforce_available_locales</code>. <h3>Caveats</h3></li> </ul> <h3>Example</h3> <pre><code>require File.expand_path('../boot', __FILE__) # ... module YouApplication class Application &lt; Rails::Application # ... config.i18n.enforce_available_locales = true # or if one of your gem compete for pre-loading, use I18n.config.enforce_available_locales = true # ... end end </code></pre> <h2>Long answer</h2> <p>The deprecation warning is now displayed both in Rails 4 (>= 4.0.2) and Rails 3.2 (>= 3.2.14). The reason is explained in <a href="https://github.com/svenfuchs/i18n/commit/3b6e56e06fd70f6e4507996b017238505e66608c" rel="noreferrer">this commit</a>.</p> <blockquote> <p>Enforce available locales</p> <p>When <code>I18n.config.enforce_available_locales</code> is true we'll raise an I18n::InvalidLocale exception if the passed locale is unavailable.</p> <p>The default is set to <code>nil</code> which will display a deprecation error.</p> <p>If set to <code>false</code> we'll skip enforcing available locales altogether (old behaviour).</p> <p>This has been implemented in the following methods :</p> <ul> <li>I18n.config.default_locale=</li> <li>I18n.config.locale=</li> <li>I18n.translate</li> <li>I18n.localize</li> <li>I18n.transliterate</li> </ul> </blockquote> <p>Before this change, if you passed an unsupported locale, Rails would silently switch to it if the locale is valid (i.e. if there is a corresponding locale file in the <code>/config/locales</code> folder), otherwise the locale would default to the <code>config.i18n.default_locale</code> configuration (which defaults to :en).</p> <p>The new version of the I18n gem, forces developers to be a little bit more conscious of the locale management.</p> <p>In the future, the behavior will change and if a locale is invalid, the Rails app will raise an error. </p> <p>In preparation of such change (that may potentially break several applications that until today were relying on silent defaults), the warning is forcing you to explicitly declare which validation you want to perform, during the current transition period.</p> <p>To restore the previous behavior, simply set the following configuration to <code>false</code></p> <pre><code>config.i18n.enforce_available_locales = false </code></pre> <p>otherwise, set it to true to match the new Rails defaults or if you want to be more rigid on domain validation and avoid switching to the default in case of invalid locale.</p> <pre><code>config.i18n.enforce_available_locales = true </code></pre> <h3>Caveat</h3> <ol> <li><p>If you are setting the <code>config.i18n.default_locale</code> configuration or using any of the previously mentioned methods (<code>default_locale=</code>, <code>locale=</code>, <code>translate</code>, etc), make sure to do it after setting the <code>config.i18n.enforce_available_locales</code> setting. Otherwise, the deprecation warning will keep on popping up. (Thanks <a href="https://stackoverflow.com/users/292586/fabio-batista">Fábio Batista</a>).</p></li> <li><p>If you use third party gems that include I18n features, setting the variable through may not have effect. In fact, the issue is the same as described in the previous point, just a little bit harder to debug. </p> <p>This issue is a matter of precedence. When you set the config in your Rails app, the value is not immediately assigned to the I18n gem. Rails stores each config in an internal object, loads the dependencies (Railties and third party gems) and then it passes the configuration to the target classes. If you use a gem (or Rails plugin) that calls any of the I18n methods before the config is assigned to I18n, then you'll get the warning.</p> <p>In this case, you need to skip the Rails stack and set the config immediately to the I18n gem by calling</p> <pre><code>I18n.config.enforce_available_locales = true </code></pre> <p>instead of</p> <pre><code>config.i18n.enforce_available_locales = true </code></pre> <p>The issue is easy to prove. Try to generate a new empty Rails app and you will see that setting <code>config.i18n</code> in the <code>application.rb</code> works fine.</p> <p>If in your app it does not, there is an easy way to debug the culprit. Locate the i18n gem in your system, open the <code>i18n.rb</code> file and edit the method <code>enforce_available_locales!</code> to include the statement <code>puts caller.inspect</code>.</p> <p><img src="https://i.stack.imgur.com/qukFy.png" alt=""></p> <p>This will cause the method to print the stacktrace whenever invoked. You will be able to determine which gem is calling it by inspecting the stacktrace (in my case it was Authlogic).</p> <pre><code>["/Users/weppos/.rvm/gems/ruby-2.0.0-p247@application/gems/i18n-0.6.9/lib/i18n.rb:150:in `translate'", "/Users/weppos/.rvm/gems/ruby-2.0.0-p247@application/gems/authlogic-3.1.0/lib/authlogic/i18n/translator.rb:8:in `translate'", "/Users/weppos/.rvm/gems/ruby-2.0.0-p247@application/gems/authlogic-3.1.0/lib/authlogic/i18n.rb:79:in `translate'", "/Users/weppos/.rvm/gems/ruby-2.0.0-p247@application/gems/authlogic-3.1.0/lib/authlogic/acts_as_authentic/email.rb:68:in `validates_format_of_email_field_options'", "/Users/weppos/.rvm/gems/ruby-2.0.0-p247@application/gems/authlogic-3.1.0/lib/authlogic/acts_as_authentic/email.rb:102:in `block in included'", "/Users/weppos/.rvm/gems/ruby-2.0.0-p247@application/gems/authlogic-3.1.0/lib/authlogic/acts_as_authentic/email.rb:99:in `class_eval'", "/Users/weppos/.rvm/gems/ruby-2.0.0-p247@application/gems/authlogic-3.1.0/lib/authlogic/acts_as_authentic/email.rb:99:in `included'", "/Users/weppos/.rvm/gems/ruby-2.0.0-p247@application/gems/authlogic-3.1.0/lib/authlogic/acts_as_authentic/base.rb:37:in `include'", "/Users/weppos/.rvm/gems/ruby-2.0.0-p247@application/gems/authlogic-3.1.0/lib/authlogic/acts_as_authentic/base.rb:37:in `block in acts_as_authentic'", "/Users/weppos/.rvm/gems/ruby-2.0.0-p247@application/gems/authlogic-3.1.0/lib/authlogic/acts_as_authentic/base.rb:37:in `each'", "/Users/weppos/.rvm/gems/ruby-2.0.0-p247@application/gems/authlogic-3.1.0/lib/authlogic/acts_as_authentic/base.rb:37:in `acts_as_authentic'", "/Users/weppos/Projects/application/app/models/user.rb:8:in `&lt;class:User&gt;'", "/Users/weppos/Projects/application/app/models/user.rb:1:in `&lt;top (required)&gt;'", </code></pre></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload