Changed translations to actually translate upon requesting the label

and not upon creating the class causing language changes in production
to have no effect
pull/6827/head
Sebastian Schuster 12 years ago
parent f71001dc15
commit e28bbe9923
  1. 5
      lib/report/chainable.rb
  2. 58
      lib/report/operator.rb
  3. 2
      lib/widget/filters/operators.rb

@ -84,9 +84,12 @@ class Report < ActiveRecord::Base
@cache_key ||= underscore_name
end
inherited_attribute :label, :default => "Translation needed"
inherited_attribute :properties, :list => true
def self.label
"Translation needed"
end
class << self
alias inherited_attributes inherited_attribute
alias accepts_properties accepts_property

@ -31,14 +31,14 @@ class Report::Operator
end
# Operators from Redmine
new ">t-", :label => I18n.t(:label_less_than_ago) do
new ">t-", :label => :label_less_than_ago do
include DateRange
def modify(query, field, value)
super query, field, -value.to_i, 0
end
end
new "w", :arity => 0, :label => I18n.t(:label_this_week) do
new "w", :arity => 0, :label => :label_this_week do
def modify(query, field, offset = nil)
offset ||= 0
first_day = begin
@ -53,16 +53,16 @@ class Report::Operator
end
end
new "t+", :label => I18n.t(:label_in) do
new "t+", :label => :label_in do
include DateRange
def modify(query, field, *values)
super query, field, values.first.to_i, values.first.to_i
end
end
new "<=", :label => I18n.t(:label_less_or_equal)
new "<=", :label => :label_less_or_equal
new "!", :label => I18n.t(:label_not_equals) do
new "!", :label => :label_not_equals do
def modify(query, field, *values)
where_clause = "(#{field} IS NULL"
where_clause += " OR #{field} NOT IN #{collection(*values)}" unless values.compact.empty?
@ -72,14 +72,14 @@ class Report::Operator
end
end
new "t-", :label => I18n.t(:label_ago) do
new "t-", :label => :label_ago do
include DateRange
def modify(query, field, *values)
super query, field, -values.first.to_i, -values.first.to_i
end
end
new "!~", :arity => 1, :label => I18n.t(:label_not_contains) do
new "!~", :arity => 1, :label => :label_not_contains do
def modify(query, field, *values)
value = values.first || ''
query.where "LOWER(#{field}) NOT LIKE '%#{quote_string(value.to_s.downcase)}%'"
@ -87,7 +87,7 @@ class Report::Operator
end
end
new "=", :label => I18n.t(:label_equals) do
new "=", :label => :label_equals do
def modify(query, field, *values)
case
when values.size == 1 && values.first.nil?
@ -101,7 +101,7 @@ class Report::Operator
end
end
new "~", :arity => 1, :label => I18n.t(:label_contains) do
new "~", :arity => 1, :label => :label_contains do
def modify(query, field, *values)
value = values.first || ''
query.where "LOWER(#{field}) LIKE '%#{quote_string(value.to_s.downcase)}%'"
@ -109,70 +109,70 @@ class Report::Operator
end
end
new "<t+", :label => I18n.t(:label_in_less_than) do
new "<t+", :label => :label_in_less_than do
include DateRange
def modify(query, field, value)
super query, field, 0, value.to_i
end
end
new "t", :label => I18n.t(:label_today) do
new "t", :label => :label_today do
include DateRange
def modify(query, field)
super query, field, 0, 0
end
end
new ">=", :label => I18n.t(:label_greater_or_equal)
new ">=", :label => :label_greater_or_equal
new "!*", :arity => 0, :where_clause => "%s IS NULL", :label => I18n.t(:label_none)
new "!*", :arity => 0, :where_clause => "%s IS NULL", :label => :label_none
new "<t-", :label => I18n.t(:label_more_than_ago) do
new "<t-", :label => :label_more_than_ago do
include DateRange
def modify(query, field, value)
super query, field, nil, -value.to_i
end
end
new ">t+", :label => I18n.t(:label_in_more_than) do
new ">t+", :label => :label_in_more_than do
include DateRange
def modify(query, field, value)
super query, field, value.to_i, nil
end
end
new "*", :arity => 0, :where_clause => "%s IS NOT NULL", :label => I18n.t(:label_all)
new "*", :arity => 0, :where_clause => "%s IS NOT NULL", :label => :label_all
# Our own operators
new "<", :label => I18n.t(:label_less)
new ">", :label => I18n.t(:label_greater)
new "<", :label => :label_less
new ">", :label => :label_greater
new "=n", :label => I18n.t(:label_equals) do
new "=n", :label => :label_equals do
def modify(query, field, value)
query.where "#{field} = #{clean_currency(value)}"
query
end
end
new "0", :label => I18n.t(:label_none), :where_clause => "%s = 0"
new "y", :label => I18n.t(:label_yes), :arity => 0, :where_clause => "%s IS NOT NULL"
new "n", :label => I18n.t(:label_no), :arity => 0, :where_clause => "%s IS NULL"
new "0", :label => :label_none, :where_clause => "%s = 0"
new "y", :label => :label_yes, :arity => 0, :where_clause => "%s IS NOT NULL"
new "n", :label => :label_no, :arity => 0, :where_clause => "%s IS NULL"
new "<d", :label => I18n.t(:label_less_or_equal), :validate => :dates do
new "<d", :label => :label_less_or_equal, :validate => :dates do
def modify(query, field, value)
return query if value.to_s.empty?
"<=".to_operator.modify query, field, quoted_date(value)
end
end
new ">d", :label => I18n.t(:label_greater_or_equal), :validate => :dates do
new ">d", :label => :label_greater_or_equal, :validate => :dates do
def modify(query, field, value)
return query if value.to_s.empty?
">=".to_operator.modify query, field, quoted_date(value)
end
end
new "<>d", :label => I18n.t(:label_between), :validate => :dates do
new "<>d", :label => :label_between, :validate => :dates do
def modify(query, field, from, to)
return query if from.to_s.empty? || to.to_s.empty?
query.where "#{field} BETWEEN '#{quoted_date from}' AND '#{quoted_date to}'"
@ -180,14 +180,14 @@ class Report::Operator
end
end
new "=d", :label => I18n.t(:label_date_on), :validate => :dates do
new "=d", :label => :label_date_on, :validate => :dates do
def modify(query, field, value)
return query if value.to_s.empty?
"=".to_operator.modify query, field, quoted_date(value)
end
end
new ">=d", :label => I18n.t(:label_days_ago), :validate => :integers do
new ">=d", :label => :label_days_ago, :validate => :integers do
force! :integers
def modify(query, field, value)
@ -197,7 +197,7 @@ class Report::Operator
end
end
new "?=", :label => I18n.t(:label_null_or_equal) do
new "?=", :label => :label_null_or_equal do
def modify(query, field, *values)
where_clause = "(#{field} IS NULL"
where_clause += " OR #{field} IN #{collection(*values)}" unless values.compact.empty?
@ -207,7 +207,7 @@ class Report::Operator
end
end
new "?!", :label => I18n.t(:label_not_null_and_not_equal) do
new "?!", :label => :label_not_null_and_not_equal do
def modify(query, field, *values)
where_clause = "(#{field} IS NOT NULL"
where_clause += " AND #{field} NOT IN #{collection(*values)}" unless values.compact.empty?

@ -17,7 +17,7 @@ class Widget::Filters::Operators < Widget::Filters::Base
opts = {:value => h(o.to_s), :"data-arity" => o.arity}
opts.reverse_merge! :"data-forced" => o.forced if o.forced?
opts[:selected] = "selected" if filter.operator.to_s == o.to_s
content_tag(:option, opts) { h(o.label) }
content_tag(:option, opts) { h(I18n.t(o.label)) }
end.join.html_safe
end
label1 = content_tag :label,

Loading…
Cancel
Save