Permalink
Browse files

When translating between two different locales - only show keys that …

…have texts in the locale being translated from
  • Loading branch information...
1 parent 65c937e commit cbbc29e348403d0a4a6277c276a3eeac1996b6b4 Peter Marklund committed Mar 19, 2009
Showing with 25 additions and 9 deletions.
  1. +4 −2 lib/translate_controller.rb
  2. +21 −7 spec/controllers/translate_controller_spec.rb
@@ -28,8 +28,10 @@ def translate
def initialize_keys
translate_keys = Translate::Keys.new
@files = translate_keys.files
- @keys = (@files.keys.map(&:to_s) +
- [:en, default_locale].uniq.map { |locale| translate_keys.i18n_keys(locale) }.flatten).uniq
+ @keys = (@files.keys.map(&:to_s) + translate_keys.i18n_keys(@from_locale)).uniq
+ @keys.reject! do |key|
+ !lookup(@from_locale, key).present?
+ end if @from_locale != @to_locale
end
def remove_hash_keys
@@ -14,37 +14,38 @@
I18n.stub!(:default_locale).and_return(:sv)
end
- it "shows sorted paginated english keys from lookup and YAML files by default" do
+ it "shows sorted paginated keys from the translate from locale and extracted keys by default" do
get_page :index
assigns(:from_locale).should == :sv
assigns(:to_locale).should == :en
assigns(:files).should == files
+ assigns(:keys).sort.should == ['articles.new.page_title', 'home.page_title', 'vendor.foobar']
assigns(:paginated_keys).should == ['articles.new.page_title']
end
it "can be paginated with the page param" do
- get_page :index, :page => 3
+ get_page :index, :page => 2
assigns(:files).should == files
assigns(:paginated_keys).should == ['home.page_title']
end
it "accepts a key_pattern param with key_type=starts_with" do
- get_page :index, :key_pattern => 'general', :key_type => 'starts_with'
+ get_page :index, :key_pattern => 'articles', :key_type => 'starts_with'
assigns(:files).should == files
- assigns(:paginated_keys).should == ['general.back']
+ assigns(:paginated_keys).should == ['articles.new.page_title']
assigns(:total_entries).should == 1
end
it "accepts a key_pattern param with key_type=contains" do
- get_page :index, :key_pattern => 'page_title', :key_type => 'contains'
+ get_page :index, :key_pattern => 'page_', :key_type => 'contains'
assigns(:files).should == files
assigns(:total_entries).should == 2
assigns(:paginated_keys).should == ['articles.new.page_title']
end
it "accepts a filter=untranslated param" do
get_page :index, :filter => 'untranslated'
- assigns(:total_entries).should == 3
+ assigns(:total_entries).should == 2
assigns(:paginated_keys).should == ['articles.new.page_title']
end
@@ -58,7 +59,20 @@ def i18n_translations
HashWithIndifferentAccess.new({
:en => {
:vendor => {
- :foobar => "Foooo"
+ :foobar => "Foo Baar"
+ }
+ },
+ :sv => {
+ :articles => {
+ :new => {
+ :page_title => "Skapa ny artikel"
+ }
+ },
+ :home => {
+ :page_title => "Välkommen till I18n"
+ },
+ :vendor => {
+ :foobar => "Fobar"
}
}
})

0 comments on commit cbbc29e

Please sign in to comment.