Translating Rails Timezones

前端 未结 9 669
滥情空心
滥情空心 2021-02-05 11:09

We internationalized our site months ago, but forgot one part: The drop down where a user picks their timezone.

How do you translate the following line:



        
9条回答
  •  一整个雨季
    2021-02-05 11:37

    fishwebby's solution didn't work for me when priority time zones where provided in the time_zone_select. Easiest is to just stick this in /config/initializers/time_zone_patch.rb :

      # See https://stackoverflow.com/questions/1396623/translating-rails-timezones
      class ActiveSupport::TimeZone
        def to_s
          offset = "(GMT#{formatted_offset})"
          translated_name = I18n.t(name, :scope => :time_zones, :default => name)
          %(#{offset} #{translated_name})
        end
      end
    

    No need to modify your view code either.

    You can use it in conjunction with this fork of the rails-i18n gem. It includes the spanish timezone translations that were provided in another response to this question. I will be adding more translations as needed or as provided until the original gem authors merge the timezones into their project.

提交回复
热议问题