Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Lookup translations for localized date/time formats only when necessa…

…ry. (thanks to http://github.com/abriening)
  • Loading branch information...
commit 6114aafb746665b151495f13eb88fb32690ef0e8 1 parent 298b982
@svenfuchs authored
Showing with 5 additions and 7 deletions.
  1. +5 −7 lib/i18n/backend/simple.rb
View
12 lib/i18n/backend/simple.rb
@@ -50,14 +50,12 @@ def localize(locale, object, format = :default, options={})
format = resolve(locale, object, format, options.merge(:raise => true))
- # TODO only translate these if the format string is actually present
# TODO check which format strings are present, then bulk translate them, then replace them
-
- format.gsub!(/%a/, translate(locale, :"date.abbr_day_names", :format => format)[object.wday])
- format.gsub!(/%A/, translate(locale, :"date.day_names", :format => format)[object.wday])
- format.gsub!(/%b/, translate(locale, :"date.abbr_month_names", :format => format)[object.mon])
- format.gsub!(/%B/, translate(locale, :"date.month_names", :format => format)[object.mon])
- format.gsub!(/%p/, translate(locale, :"time.#{object.hour < 12 ? :am : :pm}", :format => format)) if object.respond_to?(:hour)
+ format.gsub!(/%a/, translate(locale, :"date.abbr_day_names", :format => format)[object.wday]) if format.include?('%a')
+ format.gsub!(/%A/, translate(locale, :"date.day_names", :format => format)[object.wday]) if format.include?('%A')
+ format.gsub!(/%b/, translate(locale, :"date.abbr_month_names", :format => format)[object.mon]) if format.include?('%b')
+ format.gsub!(/%B/, translate(locale, :"date.month_names", :format => format)[object.mon]) if format.include?('%B')
+ format.gsub!(/%p/, translate(locale, :"time.#{object.hour < 12 ? :am : :pm}", :format => format)) if format.include?('%p') && object.respond_to?(:hour)
object.strftime(format)
end
Please sign in to comment.
Something went wrong with that request. Please try again.