LocalizationSimplified Really simple localization for Rails By Jesper Rønn-Jensen ( justaddwater.dk/ ) Plugin available at rubyforge.org/projects/l10n-simplified/
| About | = | { :lang => "cf", :updated => "2006-09-07" |
| About | = | { :lang => "chef", :updated => "2006-09-07" |
| About | = | { :lang => "da", :updated => "2006-09-07" |
| About | = | { :lang => "de", :updated => "2006-09-07" |
| About | = | { :lang => "en", :updated => "2006-09-01" |
| About | = | { :lang => "es", :updated => "2006-09-07" |
| About | = | { :lang => "fi", :updated => "2006-09-07" |
| About | = | { :lang => "fr", :updated => "2006-09-03" |
| About | = | { :lang => "fr", :updated => "2006-08-24" |
| About | = | { :lang => "nl", :updated => "2006-08-23" |
| About | = | { :lang => "pirate", :updated => "2006-09-07" |
| About | = | { :lang => "se", :updated => "2006-09-07" |
| About | = | { :lang => "en",#add locale code here :updated => "2006-09-01" |
Modify DateHelper distance_of_time_in_words
# File lib/localization_simplified.rb, line 20
20: def self.distance_of_time_in_words(from_time, to_time = 0, include_seconds = false)
21: from_time = from_time.to_time if from_time.respond_to?(:to_time)
22: to_time = to_time.to_time if to_time.respond_to?(:to_time)
23: distance_in_minutes = (((to_time - from_time).abs)/60).round
24: distance_in_seconds = ((to_time - from_time).abs).round
25:
26: #First, I invent a variable (makes it easier for future i10n)
27: messages = LocalizationSimplified::DateHelper::Texts #localized
28: case distance_in_minutes
29: when 0..1
30: return (distance_in_minutes==0) ? messages[:less_than_a_minute] : messages[:one_minute] unless include_seconds
31: case distance_in_seconds
32: when 0..5 then format( messages[:less_than_x_seconds], 5 )
33: when 6..10 then format( messages[:less_than_x_seconds], 10 )
34: when 11..20 then format( messages[:less_than_x_seconds], 20 )
35: when 21..40 then messages[:half_a_minute]
36: when 41..59 then messages[:less_than_a_minute]
37: else messages[:one_minute]
38: end
39:
40: when 2..45 then format(messages[:x_minutes], distance_in_minutes)
41: when 46..90 then messages[:one_hour]
42: when 90..1440 then format( messages[:x_hours], (distance_in_minutes.to_f / 60.0).round )
43: when 1441..2880 then messages[:one_day]
44: else format( messages[:x_days], (distance_in_minutes / 1440).round )
45: end
46: end
substitute all daynames and monthnames with localized names from RUtils plugin
# File lib/localization_simplified.rb, line 10
10: def self.localize_strftime(date='%d.%m.%Y', time='')
11: date.gsub!(/%%/, @@ignore)
12: date.gsub!(/%a/, LocalizationSimplified::DateHelper::AbbrDaynames[time.wday])
13: date.gsub!(/%A/, LocalizationSimplified::DateHelper::Daynames[time.wday])
14: date.gsub!(/%b/, LocalizationSimplified::DateHelper::AbbrMonthnames[time.mon])
15: date.gsub!(/%B/, LocalizationSimplified::DateHelper::Monthnames[time.mon])
16: date.gsub!(@@ignore, '%%')
17: end