Module | ArkanisDevelopment::SimpleLocalization::LocalizedDateHelpers |
In: |
lib/features/localized_date_helpers.rb
|
Localizes the date_select helper by loading the default options from the language file.
# File lib/features/localized_date_helpers.rb, line 46 46: def date_select(object_name, method, options = {}) 47: options = Language[:helpers, :date_select].symbolize_keys.update(options) 48: super object_name, method, options 49: end
Localizes the distance_of_time_in_words helper by reimplementing it and loading the strings from the language file.
# File lib/features/localized_date_helpers.rb, line 53 53: def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false) 54: from_time = from_time.to_time if from_time.respond_to?(:to_time) 55: to_time = to_time.to_time if to_time.respond_to?(:to_time) 56: distance_in_minutes = (((to_time - from_time).abs)/60).round 57: distance_in_seconds = ((to_time - from_time).abs).round 58: 59: lang = Language[:helpers, :distance_of_time_in_words] 60: 61: case distance_in_minutes 62: when 0..1 63: return (distance_in_minutes == 0) ? lang['less than a minute'] : lang['1 minute'] unless include_seconds 64: case distance_in_seconds 65: when 0..4 then lang['less than 5 seconds'] 66: when 5..9 then lang['less than 10 seconds'] 67: when 10..19 then lang['less than 20 seconds'] 68: when 20..39 then lang['half a minute'] 69: when 40..59 then lang['less than a minute'] 70: else lang['1 minute'] 71: end 72: 73: when 2..44 then format(lang['n minutes'], distance_in_minutes) 74: when 45..89 then lang['about 1 hour'] 75: when 90..1439 then format(lang['about n hours'], (distance_in_minutes.to_f / 60.0).round) 76: when 1440..2879 then lang['1 day'] 77: when 2880..43199 then format(lang['n days'], (distance_in_minutes / 1440).round) 78: when 43200..86399 then lang['about 1 month'] 79: when 86400..525959 then format(lang['n months'], (distance_in_minutes / 43200).round) 80: when 525960..1051919 then lang['about 1 year'] 81: else 82: years = (distance_in_minutes / 525960).round 83: format(lang["over #{years} years"] || lang['over n years'], years) 84: end 85: end