2016-04-08 14:49:50 -04:00
|
|
|
require 'js_locale_helper'
|
|
|
|
|
2015-11-13 16:34:13 -05: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 }
|
2016-04-08 14:49:50 -04:00
|
|
|
|
|
|
|
data = { value: value }
|
|
|
|
if key.end_with?('_MF')
|
|
|
|
data[:compiled_js] = JsLocaleHelper.compile_message_format(locale, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
row_count = where(params).update_all(data)
|
|
|
|
create!(params.merge(data)) if row_count == 0
|
2015-11-20 12:30:04 -05:00
|
|
|
i18n_changed
|
|
|
|
end
|
2015-11-17 16:14:42 -05:00
|
|
|
|
2015-11-20 12:30:04 -05:00
|
|
|
def self.revert!(locale, *keys)
|
|
|
|
TranslationOverride.where(locale: locale, translation_key: keys).delete_all
|
|
|
|
i18n_changed
|
2015-11-13 16:34:13 -05:00
|
|
|
end
|
|
|
|
|
2015-11-20 12:30:04 -05:00
|
|
|
protected
|
|
|
|
|
|
|
|
def self.i18n_changed
|
|
|
|
I18n.reload!
|
|
|
|
MessageBus.publish('/i18n-flush', { refresh: true })
|
|
|
|
end
|
|
|
|
|
2015-11-13 16:34:13 -05:00
|
|
|
end
|
2016-01-11 01:30:56 -05:00
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: translation_overrides
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# locale :string not null
|
|
|
|
# translation_key :string not null
|
|
|
|
# value :string not null
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_translation_overrides_on_locale_and_translation_key (locale,translation_key) UNIQUE
|
|
|
|
#
|