-
-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ERROR] request#show (NoMethodError) "undefined method `strip' for nil:NilClass" #5382
Comments
This only happens in an alternative locale: r = InfoRequest.find_by url_title: 'demande_de_la_composition_de'
r.incoming_messages.last.specific_from_name?
# => true
AlaveteliLocalization.with_locale('nl_BE') { r.incoming_messages.last.specific_from_name? }
# => NoMethodError: undefined method `strip' for nil:NilClass |
Lets look at what's going on here: # class IncomingMessage…
def specific_from_name?
!safe_mail_from.nil? && safe_mail_from.strip != info_request.public_body.name.strip
end We have a m = r.incoming_messages.last
m.safe_mail_from
# => "Info Controleorgaan" But we only have a m.info_request.public_body.name
# => "Organe de controle de l'information policière"
AlaveteliLocalization.with_locale('nl_BE') { m.info_request.public_body.name }
# => nil …so we're trying to call |
I think this is actually a problem with underscore locales. When we have a b.translated_locales
# => [:en]
b.name(:en)
# => "Foo"
b.name(:es)
# => "Foo" With underscore locales, we don't get the fallback: b.translated_locales
# => [:fr_BE]
b.name(:fr_BE)
# => "Organe de controle de l'information policière"
b.name(:nl_BE)
# => nil |
Yep. In this case, I18n.fallbacks
# => { :fr_BE => [:fr_BE, :"fr-BE", :fr],
# :nl_BE => [:nl_BE, :"fr-BE", :fr] }
AlaveteliLocalization.with_locale(:fr_BE) { Globalize.fallbacks }
# => [:fr_BE, :"fr-BE", :fr]
AlaveteliLocalization.with_locale(:nl_BE) { Globalize.fallbacks }
# => [:nl_BE, :"fr-BE", :fr] |
Manually including fallbacks = {
fr_BE: [:fr_BE, :"fr-BE", :fr],
nl_BE: [:nl_BE, :fr_BE, :"fr-BE", :fr]
}
Globalize.fallbacks = fallbacks
# => {:fr_BE=>[:fr_BE, :"fr-BE", :fr], :nl_BE=>[:nl_BE, :fr_BE, :"fr-BE", :fr]}
b.name(:fr_BE)
# => "Organe de controle de l'information policière"
b.name(:nl_BE)
# => "Organe de controle de l'information policière" |
Also seeing these in Rwanda (likely because it has an underscore locale as the default locale). Similar cause as #5890. More info in https://github.com/mysociety/alaveteli/wiki/Translations-and-underscore-locales. |
When a site has an underscore locale (e.g. "fr_BE") set as the default, it is not included in the I18n fallbacks for non-default locales. I18n.fallbacks # => { :fr_BE => [:fr_BE, :"fr-BE", :fr], # :nl_BE => [:nl_BE, :"fr-BE", :fr] } AlaveteliLocalization.with_locale(:fr_BE) { Globalize.fallbacks } # => [:fr_BE, :"fr-BE", :fr] AlaveteliLocalization.with_locale(:nl_BE) { Globalize.fallbacks } # => [:nl_BE, :"fr-BE", :fr] In the example above, this means that a missing model translation when using the "nl_BE" locale will **not** correctly fall back to the translation for the default locale ("fr_BE"). This commit ensures that the default locale is always available in the fallbacks for non-default locales. We try to add it before the non-underscore version so that the regional translation is preferred, with the non-regional fallback available as a last-ditch attempt to find a useful translation. Fixes #5382
When a site has an underscore locale (e.g. "fr_BE") set as the default, it is not included in the I18n fallbacks for non-default locales. I18n.fallbacks # => { :fr_BE => [:fr_BE, :"fr-BE", :fr], # :nl_BE => [:nl_BE, :"fr-BE", :fr] } AlaveteliLocalization.with_locale(:fr_BE) { Globalize.fallbacks } # => [:fr_BE, :"fr-BE", :fr] AlaveteliLocalization.with_locale(:nl_BE) { Globalize.fallbacks } # => [:nl_BE, :"fr-BE", :fr] In the example above, this means that a missing model translation when using the "nl_BE" locale will **not** correctly fall back to the translation for the default locale ("fr_BE"). This commit ensures that the default locale is always available in the fallbacks for non-default locales. We try to add it before the non-underscore version so that the regional translation is preferred, with the non-regional fallback available as a last-ditch attempt to find a useful translation. Fixes #5382
When a site has an underscore locale (e.g. "fr_BE") set as the default, it is not included in the I18n fallbacks for non-default locales. I18n.fallbacks # => { :fr_BE => [:fr_BE, :"fr-BE", :fr], # :nl_BE => [:nl_BE, :"fr-BE", :fr] } AlaveteliLocalization.with_locale(:fr_BE) { Globalize.fallbacks } # => [:fr_BE, :"fr-BE", :fr] AlaveteliLocalization.with_locale(:nl_BE) { Globalize.fallbacks } # => [:nl_BE, :"fr-BE", :fr] In the example above, this means that a missing model translation when using the "nl_BE" locale will **not** correctly fall back to the translation for the default locale ("fr_BE"). This commit ensures that the default locale is always available in the fallbacks for non-default locales. We try to add it before the non-underscore version so that the regional translation is preferred, with the non-regional fallback available as a last-ditch attempt to find a useful translation. Fixes #5382
When a site has an underscore locale (e.g. "fr_BE") set as the default, it is not included in the I18n fallbacks for non-default locales. I18n.fallbacks # => { :fr_BE => [:fr_BE, :"fr-BE", :fr], # :nl_BE => [:nl_BE, :"fr-BE", :fr] } AlaveteliLocalization.with_locale(:fr_BE) { Globalize.fallbacks } # => [:fr_BE, :"fr-BE", :fr] AlaveteliLocalization.with_locale(:nl_BE) { Globalize.fallbacks } # => [:nl_BE, :"fr-BE", :fr] In the example above, this means that a missing model translation when using the "nl_BE" locale will **not** correctly fall back to the translation for the default locale ("fr_BE"). This commit ensures that the default locale is always available in the fallbacks for non-default locales. We try to add it before the non-underscore version so that the regional translation is preferred, with the non-regional fallback available as a last-ditch attempt to find a useful translation. Fixes #5382
When a site has an underscore locale (e.g. "fr_BE") set as the default, it is not included in the I18n fallbacks for non-default locales. I18n.fallbacks # => { :fr_BE => [:fr_BE, :"fr-BE", :fr], # :nl_BE => [:nl_BE, :"fr-BE", :fr] } AlaveteliLocalization.with_locale(:fr_BE) { Globalize.fallbacks } # => [:fr_BE, :"fr-BE", :fr] AlaveteliLocalization.with_locale(:nl_BE) { Globalize.fallbacks } # => [:nl_BE, :"fr-BE", :fr] In the example above, this means that a missing model translation when using the "nl_BE" locale will **not** correctly fall back to the translation for the default locale ("fr_BE"). This commit ensures that the default locale is always available in the fallbacks for non-default locales. We try to add it before the non-underscore version so that the regional translation is preferred, with the non-regional fallback available as a last-ditch attempt to find a useful translation. Globalize model attributes fallbacks specs contributed by @gbp. Fixes #5382 Fixes #5895
When a site has an underscore locale (e.g. "fr_BE") set as the default, it is not included in the I18n fallbacks for non-default locales. I18n.fallbacks # => { :fr_BE => [:fr_BE, :"fr-BE", :fr], # :nl_BE => [:nl_BE, :"fr-BE", :fr] } AlaveteliLocalization.with_locale(:fr_BE) { Globalize.fallbacks } # => [:fr_BE, :"fr-BE", :fr] AlaveteliLocalization.with_locale(:nl_BE) { Globalize.fallbacks } # => [:nl_BE, :"fr-BE", :fr] In the example above, this means that a missing model translation when using the "nl_BE" locale will **not** correctly fall back to the translation for the default locale ("fr_BE"). This commit ensures that the default locale is always available in the fallbacks for non-default locales. We try to add it before the non-underscore version so that the regional translation is preferred, with the non-regional fallback available as a last-ditch attempt to find a useful translation. Globalize model attributes fallbacks specs contributed by @gbp. Fixes #5382 Fixes #5895
Seeing this more on Rwanda since bumping to 0.40 and/or migrating to the new infra. |
This has an issue again since 02ea505 but only visible for us at mySociety since upgrading Belgium and Rwanda to 0.40. Both these sites have underscored locales ( It turns out calling Unfortunately we can't move to an |
Sometimes we need locales to be loaded before the application has been initialised. Setting in the in `config.before_configuration` block doesn't persist correctly and also needs to be called in after initialisation. This issue became apparent when there is an exception on boot. The error message might call `to_sentence` [1], which will load a translation and this then error if `set_locales` hasn't been called. [1]: https://github.com/rails/rails/blob/d39db5d/activestorage/lib/active_storage/service/registry.rb#L18-L19 See #5382
Sometimes we need locales to be loaded before the application has been initialised. Setting in the in `config.before_configuration` block doesn't persist correctly and also needs to be called in after initialisation. This issue becomes apparent when there is an exception at boot. The error message might call `to_sentence` [1], which will attempt to load a translation and this then error if `set_locales` hasn't been called. [1]: https://github.com/rails/rails/blob/d39db5d/activestorage/lib/active_storage/service/registry.rb#L18-L19 See #5382
Sometimes we need locales to be loaded before the application has been initialised. Setting in the in `config.before_configuration` block doesn't persist correctly and also needs to be called in after initialisation. This issue becomes apparent when there is an exception at boot. The error message might call `to_sentence` [1], which will attempt to load a translation and this then error if `set_locales` hasn't been called. [1]: https://github.com/rails/rails/blob/d39db5d/activestorage/lib/active_storage/service/registry.rb#L18-L19 See #5382
The text was updated successfully, but these errors were encountered: