Skip to content
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

fix locale fallbacks so they actually fallback #1314

Merged
merged 2 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions apps/dashboard/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

before_action :set_user, :set_pinned_apps, :set_nav_groups, :set_announcements, :set_locale
before_action :set_user, :set_pinned_apps, :set_nav_groups, :set_announcements
before_action :set_my_balances, only: [:index, :new, :featured]
before_action :set_featured_group

def set_locale
I18n.locale = ::Configuration.locale
rescue I18n::InvalidLocale => e
logger.warn "I18n::InvalidLocale #{::Configuration.locale}: #{e.message}"
end

def set_user
@user = User.new
end
Expand Down
4 changes: 1 addition & 3 deletions apps/dashboard/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ class Application < Rails::Application
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Locales are handled in config/initializers/locales.rb.

# Custom error pages
config.exceptions_app = self.routes
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/config/configuration_singleton.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def dataroot
end

def locale
(ENV['OOD_LOCALE'] || I18n.default_locale).to_sym
(ENV['OOD_LOCALE'] || 'en').to_sym
end

def locales_root
Expand Down
4 changes: 1 addition & 3 deletions apps/dashboard/config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false

# 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
# Locales are handled in config/initializers/locales.rb.

# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
Expand Down
15 changes: 6 additions & 9 deletions apps/dashboard/config/initializers/locales.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# load the fallbacks backend module
require "i18n/backend/fallbacks"
# Setup locales by adding to the locale path, setting the default and setting fallbacks

# clear the Railtie config to allow our config_root to have higher precedence
Rails.application.config.i18n = {}
extra_locales = ::Configuration.locales_root.join('*.{yml,rb}')
base_locales = Rails.application.config.root.join('config', 'locales', '*.{yml,rb}')

# replace the backend to allow missing translations to default to OOD-supplied ones
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)

# load the local translations and any translations from config_root
I18n.load_path += Dir[Rails.application.config.root.join('config', 'locales', '*.{yml,rb}'), ::Configuration.locales_root.join('*.{yml,rb}')]
Rails.application.config.i18n.load_path += Dir[base_locales, extra_locales]
Rails.application.config.i18n.default_locale = ::Configuration.locale
Rails.application.config.i18n.fallbacks = [:en]