Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make sure the ActiveRecord backend works with custom scope separators

  • Loading branch information...
commit 9341d3fcfc951cc31807ba672d2b5d90909ef3e5 1 parent 99c308e
@svenfuchs authored
View
8 lib/i18n/backend/active_record.rb
@@ -20,9 +20,9 @@ class ActiveRecord
def reload!
end
- def store_translations(locale, data)
- separator = I18n.default_separator # TODO allow to pass as an option?
- wind_keys(data).each do |key, v|
+ def store_translations(locale, data, options = {})
+ separator = options[:separator] || I18n.default_separator
+ wind_keys(data, separator).each do |key, v|
Translation.locale(locale).lookup(expand_keys(key, separator), separator).delete_all
Translation.create(:locale => locale.to_s, :key => key, :value => v)
end
@@ -55,7 +55,7 @@ def lookup(locale, key, scope = [], separator = nil)
hash[r.key.slice(chop_range)] = r.value
hash
end
- deep_symbolize_keys(unwind_keys(result))
+ deep_symbolize_keys(unwind_keys(result, separator))
end
end
View
2  lib/i18n/backend/active_record/translation.rb
@@ -57,7 +57,7 @@ class Translation < ::ActiveRecord::Base
named_scope :lookup, lambda { |keys, *separator|
keys = Array(keys).map! { |key| key.to_s }
- separator ||= I18n.default_separator
+ separator = separator.first || I18n.default_separator
{ :conditions => ["`key` IN (?) OR `key` LIKE '#{keys.last}#{separator}%'", keys] }
}
View
2  lib/i18n/backend/base.rb
@@ -21,7 +21,7 @@ def load_translations(*filenames)
# This uses a deep merge for the translations hash, so existing
# translations will be overwritten by new ones only at the deepest
# level of the hash.
- def store_translations(locale, data)
+ def store_translations(locale, data, options = {})
merge_translations(locale, data)
end
View
4 lib/i18n/backend/chain.rb
@@ -27,8 +27,8 @@ def reload!
backends.each { |backend| backend.reload! }
end
- def store_translations(locale, data)
- backends.first.store_translations(locale, data)
+ def store_translations(locale, data, options = {})
+ backends.first.store_translations(locale, data, options = {})
end
def available_locales
Please sign in to comment.
Something went wrong with that request. Please try again.