Skip to content

Commit

Permalink
Removing the private Translate::Keys#extract_i18n_keys method. It see…
Browse files Browse the repository at this point in the history
…md superfluous since we have the to_shallow_hash method
  • Loading branch information
Peter Marklund committed Feb 4, 2010
1 parent 906dd6b commit 58a9977
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 19 deletions.
16 changes: 1 addition & 15 deletions lib/translate/keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def keys

def i18n_keys(locale)
I18n.backend.send(:init_translations) unless I18n.backend.initialized?
extract_i18n_keys(I18n.backend.send(:translations)[locale.to_sym]).sort
Translate::Keys.to_shallow_hash(I18n.backend.send(:translations)[locale.to_sym]).keys.sort
end

def untranslated_keys
Expand Down Expand Up @@ -106,20 +106,6 @@ def self.deep_merge!(hash1, hash2)

private

def extract_i18n_keys(hash, parent_keys = [])
hash.inject([]) do |keys, (key, value)|
full_key = parent_keys + [key]
if value.is_a?(Hash)
# Nested hash
keys += extract_i18n_keys(value, full_key)
elsif value.present?
# String leaf node
keys << full_key.join(".")
end
keys
end
end

def extract_files
files_to_scan.inject(HashWithIndifferentAccess.new) do |files, file|
IO.read(file).scan(i18n_lookup_pattern).flatten.map(&:to_sym).each do |key|
Expand Down
4 changes: 2 additions & 2 deletions spec/keys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

it "should return all keys in the I18n backend translations hash" do
I18n.backend.should_receive(:translations).and_return(translations)
@keys.i18n_keys(:en).should == ['articles.new.page_title', 'categories.flash.created', 'home.about']
@keys.i18n_keys(:en).should == ['articles.new.page_title', 'categories.flash.created', 'empty', 'home.about']
end

describe "untranslated_keys" do
Expand All @@ -38,7 +38,7 @@

it "should return a hash with keys with missing translations in each locale" do
@keys.untranslated_keys.should == {
:sv => ['articles.new.page_title', 'categories.flash.created']
:sv => ['articles.new.page_title', 'categories.flash.created', 'empty']
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/log_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
I18n.locale = :sv
I18n.backend.store_translations(:sv, from_texts)
keys = Translate::Keys.new
@log = Translate::Log.new(:sv, :en, keys.send(:extract_i18n_keys, from_texts))
@log = Translate::Log.new(:sv, :en, Translate::Keys.to_shallow_hash(from_texts).keys)
@log.stub!(:file_path).and_return(file_path)
FileUtils.rm_f file_path
end
Expand Down
2 changes: 1 addition & 1 deletion tasks/translate.rake
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace :translate do
locale = new_translations.keys.first

overwrites = false
Translate::Keys.new.send(:extract_i18n_keys, new_translations[locale]).each do |key|
Translate::Keys.to_shallow_hash(new_translations[locale]).keys.each do |key|
new_text = key.split(".").inject(new_translations[locale]) { |hash, sub_key| hash[sub_key] }
existing_text = I18n.backend.send(:lookup, locale.to_sym, key)
if existing_text && new_text != existing_text
Expand Down

0 comments on commit 58a9977

Please sign in to comment.