From faf1dbbc417fb6eee56e6687f99c9a49454b8289 Mon Sep 17 00:00:00 2001 From: Maciej Litwiniuk Date: Fri, 24 May 2013 18:54:04 +0200 Subject: [PATCH] some cleanup + added setting asking if nil translation value should be humanized from key --- lib/lit.rb | 2 ++ lib/lit/cache.rb | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/lit.rb b/lib/lit.rb index 9722f5a7..da2725a1 100644 --- a/lib/lit.rb +++ b/lib/lit.rb @@ -5,6 +5,7 @@ module Lit mattr_accessor :authentication_function mattr_accessor :key_value_engine mattr_accessor :storage_options + mattr_accessor :humanize_key mattr_accessor :fallback class << self attr_accessor :loader @@ -13,6 +14,7 @@ def self.init @@table_exists ||= Lit::Locale.table_exists? if self.loader.nil? && @@table_exists self.loader ||= Loader.new + Lit.humanize_key = true if Lit.humanize_key.nil? #if loading all translations on start, migrations have to be performed #already, fails on first deploy #self.loader.cache.load_all_translations diff --git a/lib/lit/cache.rb b/lib/lit/cache.rb index bb327eda..96584ab8 100644 --- a/lib/lit/cache.rb +++ b/lib/lit/cache.rb @@ -62,7 +62,7 @@ def delete_key(key) key = key.to_s Lit.init.logger.info "deleting key: #{key}" @localizations.delete(key) - locale_key, key_without_locale = split_key(key) + key_without_locale = split_key(key).last @localization_keys.delete(key_without_locale) I18n.backend.reload! end @@ -132,7 +132,6 @@ def restore_hits_counter private def find_localization(locale, key_without_locale, value=nil) - org_value = value.present? ? value.dup : nil unless value.is_a?(Hash) localization_key = find_localization_key(key_without_locale) localization = Lit::Localization.where(:locale_id=>locale.id). @@ -146,7 +145,7 @@ def find_localization(locale, key_without_locale, value=nil) end value = new_value else - value = parse_value(value, locale) if value + value = parse_value(value, locale) unless value.nil? end if value.nil? if Lit.fallback @@ -158,7 +157,8 @@ def find_localization(locale, key_without_locale, value=nil) end end end - value = key_without_locale.split('.').last.humanize if value.nil? + value = key_without_locale.split('.').last.humanize if value.nil? && + Lit.humanize_key end l.default_value = value end @@ -199,7 +199,7 @@ def find_localization_key(key_without_locale) unless @localization_keys.has_key?(key_without_locale) find_or_create_localization_key(key_without_locale) else - localization_key = Lit::LocalizationKey.find_by_id(@localization_keys[key_without_locale]) || find_or_create_localization_key(key_without_locale) + Lit::LocalizationKey.find_by_id(@localization_keys[key_without_locale]) || find_or_create_localization_key(key_without_locale) end end @@ -219,7 +219,7 @@ def find_or_create_localization_key(key_without_locale) def update_hits_count(key) if @hits_counter_working - _lo_key, key_without_locale = split_key(key) + key_without_locale = split_key(key).last @hits_counter.incr('hits_counter.'+key) @hits_counter.incr('global_hits_counter.'+key_without_locale) end