Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow to search by key #17

Closed
wants to merge 1 commit into from

5 participants

@ZenCocoon

Tiny patch allowing to search phrases by key.

@elmatou

'+ 1 will be great

@bquorning

+1: I like. And I had +2 for my inferior pull request #24 – I wish I could move them here.

@yar
yar commented

+1 Please merge this.

@elmatou

it seems this project is not supported anymore....
Any replacement ?

@yar
yar commented

Why do you think it is not supported? The rails3 branch had the last commit on March 11th, 2011.

@elmatou

Since I follow this project (Automn 2010) despite the rails3 branch release (which is only a port of the plugin to rails 3), nothing appends, not any pull request discussed, nor issue discussed. basicly nothing...
You can check an alive fork here : https://github.com/ZenCocoon/tolk

@thomasdarde
Collaborator

This will be available in Tolk 1.2.0 (already merged on master : github/tolk/tolk)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 8, 2010
  1. @ZenCocoon

    Allow to search by key

    ZenCocoon authored
This page is out of date. Refresh to see the latest.
View
2  app/controllers/tolk/searches_controller.rb
@@ -3,7 +3,7 @@ class SearchesController < Tolk::ApplicationController
before_filter :find_locale
def show
- @phrases = @locale.search_phrases(params[:q], params[:scope].to_sym, params[:page])
+ @phrases = @locale.search_phrases(params[:q], params[:scope].to_sym, params[:k], params[:page])
end
private
View
7 app/models/tolk/locale.rb
@@ -138,8 +138,8 @@ def phrases_without_translation(page = nil, options = {})
result
end
- def search_phrases(query, scope, page = nil, options = {})
- return [] unless query.present?
+ def search_phrases(query, scope, key_query, page = nil, options = {})
+ return [] unless query.present? || key_query.present?
translations = case scope
when :origin
@@ -148,7 +148,8 @@ def search_phrases(query, scope, page = nil, options = {})
self.translations.containing_text(query)
end
- phrases = Tolk::Phrase.scoped(:order => 'tolk_phrases.key ASC')
+ phrases = Tolk::Phrase.scoped(:order => 'tolk_phrases.key ASC')
+ phrases = phrases.containing_text(key_query)
phrases = phrases.scoped(:conditions => ['tolk_phrases.id IN(?)', translations.map(&:phrase_id).uniq])
phrases.paginate({:page => page}.merge(options))
end
View
4 app/models/tolk/phrase.rb
@@ -18,5 +18,9 @@ def for(locale)
end
attr_accessor :translation
+
+ named_scope :containing_text, lambda { |query|
+ { :conditions => ["tolk_phrases.key LIKE ?", "%#{query}%"] }
+ }
end
end
View
2  app/views/tolk/searches/_form.html.erb
@@ -4,5 +4,7 @@
<%= scope_selector_for(@locale) %>
phrase:
<%= text_field_tag :q, params[:q] %>
+ within key:
+ <%= text_field_tag :k, params[:k] %>
<%= submit_tag "Search", :name => nil %>
<% end %>
View
4 app/views/tolk/searches/show.html.erb
@@ -36,7 +36,9 @@
<% else -%>
<%= format_i18n_value(phrase.translations.primary.text) -%>
<% end -%>
- <span class="key" title="<%= phrase.key %>"><%= truncate(phrase.key, :length => 100) %></span>
+ <span class="key" title="<%= phrase.key %>"><%= params[:k].present? ?
+ highlight(h(truncate(phrase.key, :length => 100)), params[:k]) :
+ h(truncate(phrase.key, :length => 100)) %></span>
</td>
</tr>
<% end %>
Something went wrong with that request. Please try again.