FIX: Allow message format translations to be overridden

This commit is contained in:
Robin Ward
2016-04-08 14:49:50 -04:00
parent adb3810f67
commit cc25716e47
9 changed files with 84 additions and 27 deletions

View File

@@ -1,11 +1,19 @@
require 'js_locale_helper'
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
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
i18n_changed
end