-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix locale loading when application boots
In development mode Rails might output some deprecation warnings which don't appear in test or production. It seems Rails 6 prepares these warnings ahead of time and they rely on the `#to_sentence` this in turn loads the locales and but because our gettext based strings are loaded in an initializer the available locales aren't yet set. Resulting in a error being raised with our i18n fixes. This change moves all the gettext and locale setup into a Railtie and sets everything up in a `before_configuration` block which runs before any initializers are run. Fixes: ``` ./lib/i18n_fixes.rb:54:in `available_locales': undefined method `map' for nil:NilClass (NoMethodError) ```
- Loading branch information
Showing
5 changed files
with
35 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class AlaveteliLocalization | ||
class Railtie < Rails::Railtie | ||
config.before_configuration do | ||
require 'alaveteli_localization/locale' | ||
require 'alaveteli_localization/hyphenated_locale' | ||
require 'alaveteli_localization/underscorred_locale' | ||
|
||
require 'routing_filters' | ||
require 'i18n_fixes' | ||
|
||
paths = ['locale'] | ||
paths << 'locale_alaveteli_pro' if AlaveteliConfiguration. | ||
enable_alaveteli_pro | ||
|
||
repos = paths.map do |path| | ||
FastGettext::TranslationRepository.build('app', path: path, type: :po) | ||
end | ||
AlaveteliLocalization.set_default_text_domain('app', repos) | ||
|
||
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) | ||
|
||
AlaveteliLocalization.set_default_locale_urls( | ||
AlaveteliConfiguration.include_default_locale_in_urls | ||
) | ||
|
||
AlaveteliLocalization.set_locales( | ||
AlaveteliConfiguration.available_locales, | ||
AlaveteliConfiguration.default_locale | ||
) | ||
end | ||
end | ||
end |