Created
January 12, 2009 17:16
-
-
Save andion/46063 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Localization-with-gettext-plugin setup | |
LocalizationWithGettext.config.supported_languages = %w(gl es) | |
LocalizationWithGettext.config.default_language = 'gl' | |
# Date format extensions | |
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!( | |
:default => '%d/%b/%Y %H:%M', | |
:compact => '%d/%b/%Y', | |
:weekday => '%A' , | |
:monthname => '%B' | |
) | |
# | |
# Hack the time class to translate week days | |
# | |
class Time | |
# Define the translated weekdays | |
WEEKDAYS = { | |
'en' => Date::DAYNAMES, | |
'es' => %w(Do Lu Ma Mi Ju Vi Sá), | |
'gl' => %w(Do Lu Ma Me Xo Ve Sá) | |
} | |
ABB_WEEKDAYS = { | |
'en' => Date::DAYNAMES, | |
'es' => %w(domingo lunes martes miércoles jueves viernes sábado), | |
'gl' => %w(domingo luns martes mércores xoves venres sábado) | |
} | |
# Define the translated months | |
ABBR_MONTHS = { | |
'en' => Date::ABBR_MONTHNAMES, | |
'es' => [nil] + %w(ene feb mar abr may jun jul ago sep oct nov dic), | |
'gl' => [nil] + %w(xan feb mar abr mai xuñ xul ago set out nov dec) | |
} | |
MONTHS = { | |
'en' => Date::MONTHNAMES, | |
'es' => [nil] + %w(enero febrero marzo abril mayo junio julio agosto | |
septiembre octubre noviembre diciembre), | |
'gl' => [nil] + %w(xaneiro febreiro marzo abril maio xuño xullo agosto | |
setembro outubro novembro decembro) | |
} | |
# | |
# Intercept strftime to translate the weekdays by means of an | |
# alias_method_chain | |
# | |
def strftime_with_i18n(format = nil) | |
lang = Locale.get.language | |
strftime_without_i18n(format.gsub('%A', WEEKDAYS[lang][wday]). | |
gsub('%b', ABBR_MONTHS[lang][month]). | |
gsub('%a', ABB_WEEKDAYS[lang][wday] ) | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment