lib/jekyll/language-plugin/date_localizer.rb in jekyll-language-plugin-1.1.7 vs lib/jekyll/language-plugin/date_localizer.rb in jekyll-language-plugin-1.1.8

- old
+ new

@@ -1,41 +1,29 @@ module Jekyll module LanguagePlugin module DateLocalizer def self.localize_date(date, format, context) - translation = Jekyll::LanguagePlugin::LiquidContext.get_language_data(context, 'date') + language_data = Jekyll::LanguagePlugin::LiquidContext.get_language_data(context) + translation = language_data.get('date') # validate language translation - raise Jekyll::LanguagePlugin::PluginError.new('Localized date is missing translation.') if translation.nil? || - !['abbr_daynames', 'daynames', 'abbr_monthnames', 'monthnames'].all? {|s| translation.key?(s) && translation[s].is_a?(Array) } || - translation['abbr_daynames'].size < 7 || translation['daynames'].size < 7 || - translation['abbr_monthnames'].size < 12 || translation['monthnames'].size < 12 - - #convert to extended Time class - date2 = JLPTime.at(date.to_i) - date2.strftime_translate(format, translation) - end - - class JLPTime < Time - def strftime_translate(format = '%F', translation) - result = self.strftime( - #...you replaced the language dependent parts. - format.gsub(/%([aAbB])/){ |m| - case $1 - when 'a'; translation['abbr_daynames'][self.wday] - when 'A'; translation['daynames'][self.wday] - when 'b'; translation['abbr_monthnames'][self.mon-1] - when 'B'; translation['monthnames'][self.mon-1] - else - raise Jekyll::LanguagePlugin::PluginError.new('Internal error.') - end - }) - if defined? @@encoding_converter - @@encoding_converter.iconv(result) - else - result - end + if !['abbr_daynames', 'daynames', 'abbr_monthnames', 'monthnames'].all? {|s| translation.key?(s) && translation[s].is_a?(Array) } || + translation['abbr_daynames'].size < 7 || translation['daynames'].size < 7 || + translation['abbr_monthnames'].size < 12 || translation['monthnames'].size < 12 + raise Jekyll::LanguagePlugin::PluginError.new('Localized date is missing translation.') end + + date.strftime( + format.gsub(/%([aAbB])/){ |m| + case $1 + when 'a'; translation['abbr_daynames'][date.wday] + when 'A'; translation['daynames'][date.wday] + when 'b'; translation['abbr_monthnames'][date.mon-1] + when 'B'; translation['monthnames'][date.mon-1] + else + raise Jekyll::LanguagePlugin::PluginError.new('Internal error.') + end + }) end end end end