2015-11-14 05:34:13 +08:00
|
|
|
class TranslationOverride < ActiveRecord::Base
|
|
|
|
validates_uniqueness_of :translation_key, scope: :locale
|
|
|
|
validates_presence_of :locale, :translation_key, :value
|
|
|
|
|
|
|
|
def self.upsert!(locale, key, value)
|
|
|
|
params = { locale: locale, translation_key: key }
|
|
|
|
row_count = where(params).update_all(value: value)
|
|
|
|
create!(params.merge(value: value)) if row_count == 0
|
2015-11-21 01:30:04 +08:00
|
|
|
i18n_changed
|
|
|
|
end
|
2015-11-18 05:14:42 +08:00
|
|
|
|
2015-11-21 01:30:04 +08:00
|
|
|
def self.revert!(locale, *keys)
|
|
|
|
TranslationOverride.where(locale: locale, translation_key: keys).delete_all
|
|
|
|
i18n_changed
|
2015-11-14 05:34:13 +08:00
|
|
|
end
|
|
|
|
|
2015-11-21 01:30:04 +08:00
|
|
|
protected
|
|
|
|
|
|
|
|
def self.i18n_changed
|
|
|
|
I18n.reload!
|
|
|
|
MessageBus.publish('/i18n-flush', { refresh: true })
|
|
|
|
end
|
|
|
|
|
2015-11-14 05:34:13 +08:00
|
|
|
end
|