Skip to content
Browse files

Refactoring on I18n translations. Now we got an i18n_for (private) me…

…thod to translate the labels.
  • Loading branch information...
1 parent 1c3051a commit 4791ced4cab68f442ca6ed2e7aa1cd6ad1c97aa6 Bruno Azisaka Maciel committed Nov 12, 2010
Showing with 14 additions and 7 deletions.
  1. +13 −6 lib/duration.rb
  2. +1 −1 lib/duration/version.rb
View
19 lib/duration.rb
@@ -146,11 +146,12 @@ def format(format_str)
'H' => @hours.to_s.rjust(2, '0'),
'M' => @minutes.to_s.rjust(2, '0'),
'S' => @seconds.to_s.rjust(2, '0'),
- '~s' => @seconds == 1 ? I18n.t(:second, :scope => :ruby_duration, :default => "second") : I18n.t(:seconds, :scope => :ruby_duration, :default => "seconds"),
- '~m' => @minutes == 1 ? I18n.t(:minute, :scope => :ruby_duration, :default => "minute") : I18n.t(:minutes, :scope => :ruby_duration, :default => "minutes"),
- '~h' => @hours == 1 ? I18n.t(:hour, :scope => :ruby_duration, :default => "hour") : I18n.t(:hours, :scope => :ruby_duration, :default => "hours"),
- '~d' => @days == 1 ? I18n.t(:day, :scope => :ruby_duration, :default => "day") : I18n.t(:days, :scope => :ruby_duration, :default => "days"),
- '~w' => @weeks == 1 ? I18n.t(:week, :scope => :ruby_duration, :default => "week") : I18n.t(:weeks, :scope => :ruby_duration, :default => "weeks")}
+ '~s' => i18n_for(:second),
+ '~m' => i18n_for(:minute),
+ '~h' => i18n_for(:hour),
+ '~d' => i18n_for(:day),
+ '~w' => i18n_for(:week)
+ }
format_str.gsub(/%?%(w|d|h|m|s|t|H|M|S|~(?:s|m|h|d|w))/) do |match|
match['%%'] ? match : identifiers[match[1..-1]]
@@ -178,5 +179,11 @@ def calculate!
# Gather the divided units
@weeks, @days, @hours, @minutes, @seconds = units
end
-
+
+ def i18n_for(singular)
+ plural = "#{singular}s"
+ label = send(plural) == 1 ? singular : plural
+
+ I18n.t(label, :scope => :ruby_duration, :default => label.to_s)
+ end
end
View
2 lib/duration/version.rb
@@ -1,3 +1,3 @@
class Duration
- VERSION = "0.5.2"
+ VERSION = "0.5.3"
end

0 comments on commit 4791ced

Please sign in to comment.
Something went wrong with that request. Please try again.