Skip to content

Instantly share code, notes, and snippets.

@honzasterba
Created March 29, 2011 15:19
Show Gist options
  • Save honzasterba/892543 to your computer and use it in GitHub Desktop.
Save honzasterba/892543 to your computer and use it in GitHub Desktop.
# DO NOT OPTIMIZE THIS FILE (flag for rake tasks)
cs:
datetime:
in_x_seconds:
one: za sekundu
few: za %{count} sekundy
other: za %{count} sekund
daily: denne
weekly: týdenne
monthly: měsíčne
twice_a_day: dva-krát za týden
twice_a_week: dva-krát za měsíc
once_a_while: jednou za uherský rok
distance_in_future_in_words:
half_a_minute: 'za půl minuty',
less_than_x_seconds:
one: 'asi za sekundu'
other: 'asi za %{count} sekund'
x_seconds:
one: 'za sekundu'
other: 'za %{count} sekund'
less_than_x_minutes:
one: 'za necelou minutu'
other: 'ani ne za %{count} minut'
x_minutes:
one: 'za minutu'
other: 'za %{count} minut'
about_x_hours:
one: 'asi za hodinu'
other: 'asi za %{count} hodin'
x_days:
one: 'za den'
other: 'za %{count} dny'
about_x_months:
one: 'asi za měsíc'
other: 'asi za %{count} měsíců'
x_months:
one: 'za měsíc'
other: 'za %{count} měsíů'
about_x_years:
one: 'asi za rok'
other: 'asi za %{count} let'
over_x_years:
one: 'více než za rok'
other: 'více než za %{count} let'
# DO NOT OPTIMIZE THIS FILE (flag for rake tasks)
en:
datetime:
in_x_seconds:
one: a second
other: "%{count} seconds"
daily: daily
weekly: weekly
monthly: monthly
twice_a_day: twice a day
twice_a_week: twice a week
once_a_while: once a while
distance_in_future_in_words: :distance_in_words
def time_from_now_in_words(time, include_seconds = true)
distance_of_time_in_words(time, Time.now, include_seconds, :future => true)
end
def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false, options = {})
from_time = from_time.to_time if from_time.respond_to?(:to_time)
to_time = to_time.to_time if to_time.respond_to?(:to_time)
distance_in_minutes = (((to_time - from_time).abs)/60).round
distance_in_seconds = ((to_time - from_time).abs).round
if options[:future]
scope = 'datetime.distance_in_future_in_words'
else
scope = 'datetime.distance_in_words'
end
I18n.with_options :locale => options[:locale], :scope => scope do |locale|
case distance_in_minutes
when 0..1
return distance_in_minutes == 0 ?
locale.t(:less_than_x_minutes, :count => 1) :
locale.t(:x_minutes, :count => distance_in_minutes) unless include_seconds
case distance_in_seconds
when 0..4 then locale.t :less_than_x_seconds, :count => 5
when 5..9 then locale.t :less_than_x_seconds, :count => 10
when 10..19 then locale.t :less_than_x_seconds, :count => 20
when 20..39 then locale.t :half_a_minute
when 40..59 then locale.t :less_than_x_minutes, :count => 1
else locale.t :x_minutes, :count => 1
end
when 2..44 then locale.t :x_minutes, :count => distance_in_minutes
when 45..89 then locale.t :about_x_hours, :count => 1
when 90..1439 then locale.t :about_x_hours, :count => (distance_in_minutes.to_f / 60.0).round
when 1440..2529 then locale.t :x_days, :count => 1
when 2530..43199 then locale.t :x_days, :count => (distance_in_minutes.to_f / 1440.0).round
when 43200..86399 then locale.t :about_x_months, :count => 1
when 86400..525599 then locale.t :x_months, :count => (distance_in_minutes.to_f / 43200.0).round
else
distance_in_years = distance_in_minutes / 525600
minute_offset_for_leap_year = (distance_in_years / 4) * 1440
remainder = ((distance_in_minutes - minute_offset_for_leap_year) % 525600)
if remainder < 131400
locale.t(:about_x_years, :count => distance_in_years)
elsif remainder < 394200
locale.t(:over_x_years, :count => distance_in_years)
else
locale.t(:almost_x_years, :count => distance_in_years + 1)
end
end
end
end
@kares
Copy link

kares commented Mar 29, 2011

paraada !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment