mirror of
https://github.com/discourse/discourse.git
synced 2026-07-29 15:54:48 -05:00
FIX: Couldn't migrate database from nothing due to I18n
Since I18n has a DB backend now, I've introduced a helper we can use to skip overrides in certain situations. Otherwise migration from empty databases was broken.
This commit is contained in:
@@ -5,6 +5,10 @@ module I18n
|
||||
class DiscourseI18n < I18n::Backend::Simple
|
||||
include I18n::Backend::Pluralization
|
||||
|
||||
def initialize
|
||||
@overrides_enabled = true
|
||||
end
|
||||
|
||||
def available_locales
|
||||
# in case you are wondering this is:
|
||||
# Dir.glob( File.join(Rails.root, 'config', 'locales', 'client.*.yml') )
|
||||
@@ -30,6 +34,15 @@ module I18n
|
||||
@overrides[locale]
|
||||
end
|
||||
|
||||
# In some environments such as migrations we don't want to use overrides.
|
||||
# Use this to disable them over a block of ruby code
|
||||
def overrides_disabled
|
||||
@overrides_enabled = false
|
||||
yield
|
||||
ensure
|
||||
@overrides_enabled = true
|
||||
end
|
||||
|
||||
# force explicit loading
|
||||
def load_translations(*filenames)
|
||||
unless filenames.empty?
|
||||
@@ -42,7 +55,7 @@ module I18n
|
||||
end
|
||||
|
||||
def translate(locale, key, options = {})
|
||||
overrides_for(locale)[key] || super(locale, key, options)
|
||||
(@overrides_enabled && overrides_for(locale)[key]) || super(locale, key, options)
|
||||
end
|
||||
|
||||
def exists?(locale, key)
|
||||
|
||||
Reference in New Issue
Block a user