Module GettextLocalize::TimeMethods
In: vendor/plugins/gettext_localize/lib/gettext_localize_extend.rb

localized time functions don‘t like to overwrite Date::MONTHNAMES and such because they are constants and aren‘t localized each time the constant is read so if the locale changed in the meantime they aren‘t updated

Methods

Public Instance methods

tries to read the DATE_FORMATS hash or returns empty hash

[Source]

    # File vendor/plugins/gettext_localize/lib/gettext_localize_extend.rb, line 69
69:     def date_formats(disable_locale=false)
70:       formats = self.class::DATE_FORMATS
71:       formats = formats.dup if formats.respond_to? :dup
72:       formats = {} unless formats.kind_of? Hash
73:       if disable_locale and respond_to?(:not_localized_formats) and not_localized_formats.kind_of?(Hash)
74:         formats.merge! not_localized_formats
75:       elsif respond_to?(:localized_formats) and localized_formats.kind_of?(Hash)
76:         formats.merge! localized_formats
77:       end
78:       if GettextLocalize::formats.kind_of?(Hash)
79:         formats.merge! GettextLocalize::formats
80:       end
81:       formats
82:     end

returns if a format is localized or fixed

[Source]

     # File vendor/plugins/gettext_localize/lib/gettext_localize_extend.rb, line 101
101:     def localized_format?(format_name)
102:       (
103:        !( not_localized_formats.respond_to?(:has_key?) and not_localized_formats.has_key?(format_name) ) or
104:        ( localized_formats.respond_to?(:has_key?) and localized_formats.has_key?(format_name) )
105:       )
106:     end

overwrites strftime to localize options that return strings adds format %V - returns "of %B" localized, for example in catalan "de Gener" = "of January" and "d‘Abril" = "of April"

[Source]

    # File vendor/plugins/gettext_localize/lib/gettext_localize_extend.rb, line 53
53:     def strftime_locale(format=nil,disable_locale=false)
54:       return if format.nil?
55:       format = format.dup
56:       unless disable_locale
57:         format.gsub!("%V", GettextLocalize::of_monthnames[self.mon] % '%e' )
58:         format.gsub!("%v", GettextLocalize::of_monthnames[self.mon] % '%d' )
59:         format.gsub!("%a", GettextLocalize::abbr_daynames[self.wday])
60:         format.gsub!("%A", GettextLocalize::daynames[self.wday])
61:         format.gsub!("%b", GettextLocalize::abbr_monthnames[self.mon])
62:         format.gsub!("%B", GettextLocalize::monthnames[self.mon])
63:       end
64:       strftime_nolocale(format)
65:     end

overwrites to_s to localize strftime on db we use the non localized version

[Source]

    # File vendor/plugins/gettext_localize/lib/gettext_localize_extend.rb, line 86
86:     def to_s_locale(format_name=:default,disable_locale=false)
87:       if format_name == :db
88:         disable_locale = true
89:       end
90:       if !disable_locale and !localized_format?(format_name)
91:         disable_locale = true
92:       end
93:       unless date_formats(disable_locale).has_key?(format_name)
94:         format = :default
95:       end
96:       format = date_formats(disable_locale)[format_name]
97:       strftime_locale(format,disable_locale)
98:     end

[Validate]