Skip to content

Commit

Permalink
Made I18n compatible for alternate languages
Browse files Browse the repository at this point in the history
  • Loading branch information
binarylogic committed Oct 15, 2008
1 parent cbc9630 commit a5fffb2
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rdoc
@@ -1,3 +1,7 @@
== 1.4.1 released 2008-10-08

* Extracted english text into configuration to support alternate languages.

== 1.4.0 released 2008-10-08

* Fixed bug when duping or cloning to copy over instance vars instead of method values
Expand Down
15 changes: 12 additions & 3 deletions Manifest
Expand Up @@ -22,10 +22,12 @@ lib/searchgasm/condition/less_than_or_equal_to.rb
lib/searchgasm/condition/like.rb
lib/searchgasm/condition/nil.rb
lib/searchgasm/condition/not_begin_with.rb
lib/searchgasm/condition/not_blank.rb
lib/searchgasm/condition/not_end_with.rb
lib/searchgasm/condition/not_equal.rb
lib/searchgasm/condition/not_have_keywords.rb
lib/searchgasm/condition/not_like.rb
lib/searchgasm/condition/not_nil.rb
lib/searchgasm/condition/sibling_of.rb
lib/searchgasm/condition/tree.rb
lib/searchgasm/conditions/base.rb
Expand Down Expand Up @@ -60,6 +62,8 @@ lib/searchgasm/modifiers/hour.rb
lib/searchgasm/modifiers/log.rb
lib/searchgasm/modifiers/log10.rb
lib/searchgasm/modifiers/log2.rb
lib/searchgasm/modifiers/lower.rb
lib/searchgasm/modifiers/ltrim.rb
lib/searchgasm/modifiers/md5.rb
lib/searchgasm/modifiers/microseconds.rb
lib/searchgasm/modifiers/milliseconds.rb
Expand All @@ -68,11 +72,14 @@ lib/searchgasm/modifiers/month.rb
lib/searchgasm/modifiers/octal.rb
lib/searchgasm/modifiers/radians.rb
lib/searchgasm/modifiers/round.rb
lib/searchgasm/modifiers/rtrim.rb
lib/searchgasm/modifiers/second.rb
lib/searchgasm/modifiers/sign.rb
lib/searchgasm/modifiers/sin.rb
lib/searchgasm/modifiers/square_root.rb
lib/searchgasm/modifiers/tan.rb
lib/searchgasm/modifiers/trim.rb
lib/searchgasm/modifiers/upper.rb
lib/searchgasm/modifiers/week.rb
lib/searchgasm/modifiers/year.rb
lib/searchgasm/search/base.rb
Expand All @@ -90,12 +97,11 @@ MIT-LICENSE
Rakefile
README.rdoc
test/fixtures/accounts.yml
test/fixtures/cats.yml
test/fixtures/dogs.yml
test/fixtures/orders.yml
test/fixtures/user_groups.yml
test/fixtures/users.yml
test/libs/acts_as_tree.rb
test/libs/ordered_hash.rb
test/libs/rexml_fix.rb
test/test_active_record_associations.rb
test/test_active_record_base.rb
test/test_condition_base.rb
Expand All @@ -109,4 +115,7 @@ test/test_search_conditions.rb
test/test_search_ordering.rb
test/test_search_pagination.rb
test/test_search_protection.rb
test_libs/acts_as_tree.rb
test_libs/ordered_hash.rb
test_libs/rexml_fix.rb
TODO.rdoc
49 changes: 49 additions & 0 deletions lib/searchgasm/config.rb
Expand Up @@ -154,6 +154,55 @@ def per_page_choices=(value)
@per_page_choices = value
end

def per_page_show_all_text # :nodoc:
@per_page_show_all_text ||= "Show all"
end

# The default value for the :text option for per_page_links and per_page_select when the page is nil, meaning show all.
#
# * <tt>Default:</tt> "Show all"
# * <tt>Accepts:</tt> String
def per_page_show_all_text=(value)
@per_page_show_all_text = value
end

def per_page_text # :nodoc:
@per_page_text ||= "%s per page"
end

# The default value for the :text option for per_page_links and per_page_select when the page is NOT nil. Only one substitution is
# passed, which is the per_page value.
#
# * <tt>Default:</tt> "%s per page"
# * <tt>Accepts:</tt> String with substitutions, using rubys % method for strings
def per_page_text=(value)
@per_page_text = value
end

def priority_order_by_link_activate_text # :nodoc:
@priority_order_by_link_activate_text ||= "Show %s first"
end

# The default value for the :activate_text option for priority_order_by_link
#
# * <tt>Default:</tt> "Show %s first"
# * <tt>Accepts:</tt> String with substitutions, using rubys % method for strings
def priority_order_by_link_activate_text=(value)
@priority_order_by_link_activate_text = value
end

def priority_order_by_link_deactivate_text # :nodoc:
@priority_order_by_link_deactivate_text ||= "Don't show %s first"
end

# The default value for the :deactivate_text option for priority_order_by_link
#
# * <tt>Default:</tt> "Dont' show %s first"
# * <tt>Accepts:</tt> String with substitutions, using rubys % method for strings
def priority_order_by_link_deactivate_text=(value)
@priority_order_by_link_deactivate_text = value
end

def remove_duplicates # :nodoc:
return @remove_duplicates if @set_remove_duplicates
@remove_duplicates ||= true
Expand Down
6 changes: 3 additions & 3 deletions lib/searchgasm/helpers/control_types/link.rb
Expand Up @@ -259,8 +259,8 @@ def add_order_as_link_defaults!(order_as, options = {})
def add_priority_order_by_link_defaults!(priority_order_by, priority_order_as, options = {})
add_searchgasm_control_defaults!(:priority_order_by, options)
options[:column_name] ||= determine_order_by_text(priority_order_by).downcase
options[:activate_text] ||= "Show #{options[:column_name]} first"
options[:deactivate_text] ||= "Don't show #{options[:column_name]} first"
options[:activate_text] ||= Config.priority_order_by_link_activate_text % options[:column_name]
options[:deactivate_text] ||= Config.priority_order_by_link_deactivate_text % options[:column_name]
active = deep_stringify(options[:search_obj].priority_order_by) == deep_stringify(priority_order_by) && options[:search_obj].priority_order_as == priority_order_as
options[:text] ||= active ? options[:deactivate_text] : options[:activate_text]
if active
Expand All @@ -274,7 +274,7 @@ def add_priority_order_by_link_defaults!(priority_order_by, priority_order_as, o

def add_per_page_link_defaults!(per_page, options = {})
add_searchgasm_control_defaults!(:per_page, options)
options[:text] ||= per_page.blank? ? "Show all" : "#{per_page} per page"
options[:text] ||= per_page.blank? ? Config.per_page_show_all_text : Config.per_page.text % per_page
options[:url] = searchgasm_params(options.merge(:search_params => {:per_page => per_page}))
options
end
Expand Down
2 changes: 1 addition & 1 deletion lib/searchgasm/helpers/control_types/select.rb
Expand Up @@ -44,7 +44,7 @@ def add_order_as_select_defaults!(options)

def add_per_page_select_defaults!(options)
add_per_page_links_defaults!(options)
options[:choices] = options[:choices].collect { |choice| choice.nil? ? ["Show all", choice] : ["#{choice} per page", choice]}
options[:choices] = options[:choices].collect { |choice| choice.nil? ? [Config.per_page_show_all_text, choice] : [Config.per_page_text % choice, choice]}
add_searchgasm_select_defaults!(:per_page, options)
options
end
Expand Down

0 comments on commit a5fffb2

Please sign in to comment.