Skip to content

Commit

Permalink
some cleanup + added setting asking if nil translation value should b…
Browse files Browse the repository at this point in the history
…e humanized from key
  • Loading branch information
mlitwiniuk committed May 24, 2013
1 parent e6dd0c6 commit faf1dbb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/lit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/lit/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit faf1dbb

Please sign in to comment.