Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Search phrase i18n keys #24

Closed
wants to merge 1 commit into from

4 participants

@bquorning

I added an "i18n keys" option to the search drop-down, which allows you to search the phrase keys. For example, I can search for "datetime.distance_in_words." and translate all those related phrases at the same time.

@libo

I think we need to merge this one! +1

@andmej

Great time saver. +1

@ZenCocoon

Save idea as pull request : #17

@bquorning

ZenCocoon’s patch is much better than mine. I will close this pull request and support his.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 6, 2011
  1. @bquorning
This page is out of date. Refresh to see the latest.
View
3  app/helpers/tolk/application_helper.rb
@@ -27,7 +27,8 @@ def tolk_locale_selection
def scope_selector_for(locale)
select_tag 'scope', options_for_select([[Tolk::Locale.primary_locale.language_name, "origin"],
- [locale.language_name, "target"]], params[:scope])
+ [locale.language_name, "target"],
+ ['i18n key of', "keys"]], params[:scope])
end
end
end
View
12 app/models/tolk/locale.rb
@@ -142,15 +142,17 @@ def phrases_without_translation(page = nil, options = {})
def search_phrases(query, scope, page = nil, options = {})
return [] unless query.present?
- translations = case scope
+ case scope
+ when :keys
+ phrases = Tolk::Phrase.containing_text(query)
when :origin
- Tolk::Locale.primary_locale.translations.containing_text(query)
+ translations = Tolk::Locale.primary_locale.translations.containing_text(query)
else # :target
- self.translations.containing_text(query)
+ translations = self.translations.containing_text(query)
end
- phrases = Tolk::Phrase.scoped(:order => 'tolk_phrases.key ASC')
- phrases = phrases.scoped(:conditions => ['tolk_phrases.id IN(?)', translations.map(&:phrase_id).uniq])
+ phrases ||= Tolk::Phrase.scoped(:conditions => ['tolk_phrases.id IN(?)', translations.map(&:phrase_id).uniq])
+ phrases = phrases.scoped(:order => 'tolk_phrases.key ASC')
phrases.paginate({:page => page}.merge(options))
end
View
4 app/models/tolk/phrase.rb
@@ -2,6 +2,10 @@ module Tolk
class Phrase < ActiveRecord::Base
set_table_name "tolk_phrases"
+ named_scope :containing_text, lambda { |query|
+ { :conditions => ["tolk_phrases.key LIKE ?", "%#{query}%"] }
+ }
+
validates_uniqueness_of :key
cattr_accessor :per_page
Something went wrong with that request. Please try again.