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:
I took some ideas in this post and built a gem to handle timezone translations. I've only got en and es translations right now but its pretty easy to add it to your app and add more locale. Just add this to your Gemfile:
gem i18n-timezones
You can grab the source here:
https://github.com/onomojo/i18n-timezones
I had the same problem and fishwebby's answer made the trick easily. I needed the time zones translated to spanish so here I leave the list:
"International Date Line West": "Línea de fecha internacional del oeste"
"Midway Island": "Isla de Midway"
"Samoa": "Samoa"
"Hawaii": "Hawai"
"Alaska": "Alaska"
"Pacific Time (US & Canada)": "Hora del Pacífico (EE.UU. y Canadá)"
"Tijuana": "Tijuana"
"Mountain Time (US & Canada)": "Hora de las Montañas (EE.UU. y Canadá)"
"Arizona": "Arizona"
"Chihuahua": "Chihuahua"
"Mazatlan": "Mazatlán"
"Central Time (US & Canada)": "Hora central (EE.UU. y Canadá)"
"Saskatchewan": "Saskatchewan"
"Guadalajara": "Guadalajara"
"Mexico City": "Ciudad de México"
"Monterrey": "Monterrey"
"Central America": "América Central"
"Eastern Time (US & Canada)": "Hora del Este (EE.UU. y Canadá)"
"Indiana (East)": "Indiana (Este)"
"Bogota": "Bogotá"
"Lima": "Lima"
"Quito": "Quito"
"Atlantic Time (Canada)": "Hora del Atlántico (Canadá)"
"Caracas": "Caracas"
"La Paz": "La Paz"
"Santiago": "Santiago"
"Newfoundland": "Terranova"
"Brasilia": "Brasilia"
"Buenos Aires": "Buenos Aires"
"Georgetown": "Georgetown"
"Greenland": "Groenlandia"
"Mid-Atlantic": "Atlántico medio"
"Azores": "Azores"
"Cape Verde Is.": "Isla Cabo Verde"
"Dublin": "Dublín"
"Edinburgh": "Edimburgo"
"Lisbon": "Lisboa"
"London": "Londres"
"Casablanca": "Casablanca"
"Monrovia": "Monrovia"
"UTC": "UTC"
"Belgrade": "Belgrado"
"Bratislava": "Bratislava"
"Budapest": "Budapest"
"Ljubljana": "Ljubljana"
"Prague": "Praga"
"Sarajevo": "Sarajevo"
"Skopje": "Skopje"
"Warsaw": "Varsovia"
"Zagreb": "Zagreb"
"Brussels": "Bruselas"
"Copenhagen": "Copenhague"
"Madrid": "Madrid"
"Paris": "París"
"Amsterdam": "Amsterdam"
"Berlin": "Berlín"
"Bern": "Berna"
"Rome": "Roma"
"Stockholm": "Estocolmo"
"Vienna": "Viena"
"West Central Africa": "Centro-Oeste de África"
"Bucharest": "Bucarest"
"Cairo": "El Cairo"
"Helsinki": "Helsinki"
"Kyev": "Kyev"
"Riga": "Riga"
"Sofia": "Sofía"
"Tallinn": "Tallin"
"Vilnius": "Vilnius"
"Athens": "Atenas"
"Istanbul": "Estambul"
"Minsk": "Minsk"
"Jerusalem": "Jerusalén"
"Harare": "Harare"
"Pretoria": "Pretoria"
"Moscow": "Moscú"
"St. Petersburg": "San Petersburgo"
"Volgograd": "Volgogrado"
"Kuwait": "Kuwait"
"Riyadh": "Riad"
"Nairobi": "Nairobi"
"Baghdad": "Bagdad"
"Tehran": "Teherán"
"Abu Dhabi": "Abu Dhabi"
"Muscat": "Moscatel"
"Baku": "Bakú"
"Tbilisi": "Tbilisi"
"Yerevan": "Ereván"
"Kabul": "Kabul"
"Ekaterinburg": "Ekaterinburg"
"Islamabad": "Islamabad"
"Karachi": "Karachi"
"Tashkent": "Tashkent"
"Chennai": "Chennai"
"Kolkata": "Kolkata"
"Mumbai": "Mumbai"
"New Delhi": "Nueva Delhi"
"Kathmandu": "Katmandú"
"Astana": "Astana"
"Dhaka": "Dhaka"
"Sri Jayawardenepura": "Sri Jayawardenepura"
"Almaty": "Almaty"
"Novosibirsk": "Novosibirsk"
"Rangoon": "Rangún"
"Bangkok": "Bangkok"
"Hanoi": "Hanoi"
"Jakarta": "Yakarta"
"Krasnoyarsk": "Krasnoyarsk"
"Beijing": "Beijing"
"Chongqing": "Chongqing"
"Hong Kong": "Hong Kong"
"Urumqi": "Urumqi"
"Kuala Lumpur": "Kuala Lumpur"
"Singapore": "Singapur"
"Taipei": "Taipei"
"Perth": "Perth"
"Irkutsk": "Irkutsk"
"Ulaan Bataar": "Ulán Bator"
"Seoul": "Seúl"
"Osaka": "Osaka"
"Sapporo": "Sapporo"
"Tokyo": "Tokio"
"Yakutsk": "Yakutsk"
"Darwin": "Darwin"
"Adelaide": "Adelaida"
"Canberra": "Canberra"
"Melbourne": "Melbourne"
"Sydney": "Sydney"
"Brisbane": "Brisbane"
"Hobart": "Hobart"
"Vladivostok": "Vladivostok"
"Guam": "Guam"
"Port Moresby": "Port Moresby"
"Magadan": "Magadan"
"Solomon Is.": "Islas Salomón"
"New Caledonia": "Nueva Caledonia"
"Fiji": "Fiji"
"Kamchatka": "Kamchatka"
"Marshall Is.": "Islas Marshall"
"Auckland": "Auckland"
"Wellington": "Wellington"
"Nuku'alofa": "Nuku'alofa"
The accepted answer from @DaveHollingworth worked for us under Rails 3.2, but we hit the error reported by @NazarHlynskyi when we upgraded to Rails 4.2:
NoMethodError (undefined method [] for nil:NilClass)
To work around this I have resorted to monkey patching the ActiveSupport::TimeZone
, with the #to_s
method above.
So now in config/initializers/time_zone.rb
we have the following
class ActiveSupport::TimeZone
def to_s
translated_name = I18n.t(name, :scope => :timezones, :default => name)
"(GMT#{formatted_offset}) #{translated_name}"
end
end
and we no longer have the separate I18nTimeZone
model.
Monkey-patching may not be to your liking, in which case you will probably need to get a bit more intimate with the internal changes to ActiveSupport::TimeZone
in order to recreate the behaviour, but the monkey-patching option provided a quick resolution for us.
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.
French translations:
"American Samoa": "Samoa américaines" # -11:00
#"International Date Line West": "" # -11:00
"Midway Island": "Îles Midway" # -11:00
"Hawaii": "Hawaï" # -10:00
"Alaska": "Alaska" # -09:00
"Pacific Time (US & Canada)": "Pacific Time (É.-U. et Canada)" # -08:00
"Tijuana": "Tijuana" # -08:00
"Arizona": "Arizona" # -07:00
"Chihuahua": "Chihuahua" # -07:00
"Mazatlan": "Mazatlán" # -07:00
"Mountain Time (US & Canada)": "Mountain Time (É.-U. et Canada)" # -07:00
"Central America": "Amérique centrale" # -06:00
"Central Time (US & Canada)": "Central Time (É.-U. et Canada)" # -06:00
"Guadalajara": "Guadalajara" # -06:00
"Mexico City": "Mexico" # -06:00
"Monterrey": "Monterrey" # -06:00
"Saskatchewan": "Saskatchewan" # -06:00
"Bogota": "Bogotá" # -05:00
"Eastern Time (US & Canada)": "Heure de l'Est (É.-U. et Canada)" # -05:00
"Indiana (East)": "Indiana (est)" # -05:00
"Lima": "Lima" # -05:00
"Quito": "Quito" # -05:00
"Caracas": "Caracas" # -04:30
"Atlantic Time (Canada)": "Atlantic Time (Canada)" # -04:00
"Georgetown": "Georgetown" # -04:00
"La Paz": "La Paz" # -04:00
"Santiago": "Santiago" # -04:00
"Newfoundland": "Terre-Neuve" # -03:30
"Brasilia": "Brasilia" # -03:00
"Buenos Aires": "Buenos Aires" # -03:00
"Greenland": "Groenland" # -03:00
#"Mid-Atlantic": "" # -02:00
"Azores": "Açores" # -01:00
"Cape Verde Is.": "Cap-Vert" # -01:00
"Casablanca": "Casablanca" # +00:00
"Dublin": "Dublin" # +00:00
"Edinburgh": "Édimbourg" # +00:00
"Lisbon": "Lisbonne" # +00:00
"London": "Londres" # +00:00
"Monrovia": "Monrovia" # +00:00
"UTC": "UTC" # +00:00
"Amsterdam": "Amsterdam" # +01:00
"Belgrade": "Belgrade" # +01:00
"Berlin": "Berlin" # +01:00
"Bern": "Berne" # +01:00
"Bratislava": "Bratislava" # +01:00
"Brussels": "Bruxelles" # +01:00
"Budapest": "Budapest" # +01:00
"Copenhagen": "Copenhague" # +01:00
"Ljubljana": "Ljubljana" # +01:00
"Madrid": "Madrid" # +01:00
"Paris": "Paris" # +01:00
"Prague": "Prague" # +01:00
"Rome": "Rome" # +01:00
"Sarajevo": "Sarajevo" # +01:00
"Skopje": "Skopje" # +01:00
"Stockholm": "Stockholm" # +01:00
"Vienna": "Vienne" # +01:00
"Warsaw": "Varsovie" # +01:00
"West Central Africa": "Heure d'Afrique occidentale" # +01:00
"Zagreb": "Zagreb" # +01:00
"Athens": "Athènes" # +02:00
"Bucharest": "Bucarest" # +02:00
"Cairo": "Caire" # +02:00
"Harare": "Harare" # +02:00
"Helsinki": "Helsinki" # +02:00
"Istanbul": "Istanbul" # +02:00
"Jerusalem": "Jérusalem" # +02:00
"Kyiv": "Kiev" # +02:00
"Pretoria": "Pretoria" # +02:00
"Riga": "Riga" # +02:00
"Sofia": "Sofia" # +02:00
"Tallinn": "Tallinn" # +02:00
"Vilnius": "Vilnius" # +02:00
"Baghdad": "Bagdad" # +03:00
"Kuwait": "Koweït" # +03:00
"Minsk": "Minsk" # +03:00
"Nairobi": "Nairobi" # +03:00
"Riyadh": "Riyad" # +03:00
"Tehran": "Téhéran" # +03:30
"Abu Dhabi": "Abou Dabi" # +04:00
"Baku": "Bakou" # +04:00
"Moscow": "Moscou" # +04:00
"Muscat": "Mascate" # +04:00
"St. Petersburg": "Saint-Pétersbourg" # +04:00
"Tbilisi": "Tbilissi" # +04:00
"Volgograd": "Volgograd" # +04:00
"Yerevan": "Erevan" # +04:00
"Kabul": "Kaboul" # +04:30
"Islamabad": "Islamabad" # +05:00
"Karachi": "Karachi" # +05:00
"Tashkent": "Tachkent" # +05:00
"Chennai": "Chennai" # +05:30
"Kolkata": "Calcutta" # +05:30
"Mumbai": "Bombay" # +05:30
"New Delhi": "New Delhi" # +05:30
"Sri Jayawardenepura": "Sri Jayawardenapura" # +05:30
"Kathmandu": "Katmandou" # +05:45
"Almaty": "Almaty" # +06:00
"Astana": "Astana" # +06:00
"Dhaka": "Dacca" # +06:00
"Ekaterinburg": "Iekaterinbourg" # +06:00
"Rangoon": "Rangoun" # +06:30
"Bangkok": "Bangkok" # +07:00
"Hanoi": "Hanoï" # +07:00
"Jakarta": "Jakarta" # +07:00
"Novosibirsk": "Novossibirsk" # +07:00
"Beijing": "Pékin" # +08:00
"Chongqing": "Chongqing" # +08:00
"Hong Kong": "Hong Kong" # +08:00
"Krasnoyarsk": "Krasnoïarsk" # +08:00
"Kuala Lumpur": "Kuala Lumpur" # +08:00
"Perth": "Perth" # +08:00
"Singapore": "Singapour" # +08:00
"Taipei": "Taipei" # +08:00
"Ulaan Bataar": "Oulan-Bator" # +08:00
"Urumqi": "Ürümqi" # +08:00
"Irkutsk": "Irkoutsk" # +09:00
"Osaka": "Osaka" # +09:00
"Sapporo": "Sapporo" # +09:00
"Seoul": "Séoul" # +09:00
"Tokyo": "Tokyo" # +09:00
"Adelaide": "Adélaïde" # +09:30
"Darwin": "Darwin" # +09:30
"Brisbane": "Brisbane" # +10:00
"Canberra": "Canberra" # +10:00
"Guam": "Guam" # +10:00
"Hobart": "Hobart" # +10:00
"Melbourne": "Melbourne" # +10:00
"Port Moresby": "Port Moresby" # +10:00
"Sydney": "Sydney" # +10:00
"Yakutsk": "Iakoutsk" # +10:00
"New Caledonia": "Nouvelle-Calédonie" # +11:00
"Vladivostok": "Vladivostok" # +11:00
"Auckland": "Auckland" # +12:00
"Fiji": "Fidji" # +12:00
"Kamchatka": "Kamtchatka" # +12:00
"Magadan": "Magadan" # +12:00
"Marshall Is.": "Îles_Marshall" # +12:00
"Solomon Is.": "Îles Salomon" # +12:00
"Wellington": "Wellington" # +12:00
"Nuku'alofa": "Nuku'alofa" # +13:00
"Samoa": "Samoa" # +13:00
"Tokelau Is.": "Tokelau" # +14:00
Japanese translations
ja:
timezones:
"International Date Line West": "国際日付変更線"
"Midway Island": "ミッドウェイ諸島"
"American Samoa": "米領サモア"
"Samoa": "サモア"
"Hawaii": "ハワイ"
"Alaska": "アラスカ"
"Pacific Time (US & Canada)": "太平洋標準時 (アメリカ・カナダ)"
"Tijuana": "ティファナ"
"Mountain Time (US & Canada)": "山岳部標準時 (アメリカ・カナダ)"
"Arizona": "アリゾナ"
"Chihuahua": "チワワ"
"Mazatlan": "マサトラン"
"Central Time (US & Canada ": "中部標準時 (アメリカ・カナダ)"
"Saskatchewan": "サスカチュワン"
"Guadalajara": "グアダラハラ"
"Mexico City": "メキシコシティ"
"Monterrey": "モントレー"
"Central America": "中央アメリカ"
"Eastern Time (US & Canada)": "東部標準時 (アメリカ・カナダ)"
"Indiana (East)": "インディアナ (東)"
"Bogota": "ボゴタ"
"Lima": "リマ"
"Quito": "キト"
"Atlantic Time (Canada)": "大西洋標準時 (カナダ)"
"Caracas": "カラカス"
"La Paz": "ラパス"
"Santiago": "サンティアゴ"
"Newfoundland": "ニューファンドランド"
"Brasilia": "ブラジリア"
"Buenos Aires": "ブエノスアイレス"
"Georgetown": "ジョージタウン"
"Greenland": "グリーンランド"
"Mid - Atlantic": "中部大西洋"
"Azores": "アゾレス諸島"
"Cape Verde Is": "カーボベルデ"
"Dublin": "ダブリン"
"Edinburgh": "エディンバラ"
"Lisbon": "リスボン"
"London": "ロンドン"
"Casablanca": "カサブランカ"
"Monrovia": "モンロビア"
"UTC": "協定世界時"
"Belgrade": "ベオグラード"
"Bratislava": "ブラチスラヴァ"
"Budapest": "ブダペスト"
"Ljubljana": "リュブリャナ"
"Prague": "プラハ"
"Sarajevo": "サラエボ"
"Skopje": "スコピエ"
"Warsaw": "ワルシャワ"
"Zagreb": "ザグレブ"
"Brussels": "ブリュッセル"
"Copenhagen": "コペンハーゲン"
"Madrid": "マドリード"
"Paris": "パリ"
"Amsterdam": "アムステルダム"
"Berlin": "ベルリン"
"Bern": "ベルン"
"Rome": "ローマ"
"Stockholm": "ストックホルム"
"Vienna": "ウィーン"
"West Central Africa": "西中部アフリカ"
"Bucharest": "ブカレスト"
"Cairo": "カイロ"
"Helsinki": "ヘルシンキ"
"Kyiv": "キエフ"
"Riga": "リガ"
"Sofia": "ソフィア"
"Tallinn": "タリン"
"Vilnius": "ヴィリニュス"
"Athens": "アテネ"
"Istanbul": "イスタンブル"
"Minsk": "ミンスク"
"Jerusalem": "エルサレム"
"Harare": "ハラレ"
"Pretoria": "プレトリア"
"Moscow": "モスクワ"
"St. Petersburg": "サンクトペテルブルク"
"Volgograd": "ボルゴグラード"
"Kuwait": "クウェート"
"Riyadh": "リヤド"
"Nairobi": "ナイロビ"
"Baghdad": "バグダード"
"Tehran": "テヘラン"
"Abu Dhabi": "アブダビ"
"Muscat": "マスカット"
"Baku": "バクー"
"Tbilisi": "トビリシ"
"Yerevan": "エレバン"
"Kabul": "カーブル"
"Ekaterinburg": "エカテリンブルク"
"Islamabad": "イスラマバード"
"Karachi": "カラチ"
"Tashkent": "タシュケント"
"Chennai": "チェンナイ"
"Kolkata": "コルカタ"
"Mumbai": "ムンバイ"
"New Delhi": "ニューデリー"
"Kathmandu": "カトマンズ"
"Astana": "アスタナ"
"Dhaka": "ダッカ"
"Sri Jayawardenapura": "スリジャヤワルダナプラ"
"Almaty": "アルマトイ"
"Novosibirsk": "ノヴォシビルスク"
"Rangoon": "ヤンゴン"
"Bangkok": "バンコク"
"Hanoi": "ハノイ"
"Jakarta": "ジャカルタ"
"Krasnoyarsk": "クラスノヤルスク"
"Beijing": "北京市"
"Chongqing": "重慶市"
"Hong Kong": "香港"
"Urumqi": "ウルムチ市"
"Kuala Lumpur": "クアラルンプール"
"Singapore": "シンガポール"
"Taipei": "台北市"
"Perth": "パース"
"Irkutsk": "イルクーツク"
"Ulaan Bataar": "ウランバートル"
"Seoul": "ソウル"
"Osaka": "大阪"
"Sapporo": "札幌"
"Tokyo": "東京"
"Yakutsk": "ヤクーツク"
"Darwin": "ダーウィン"
"Adelaide": "アデレード"
"Canberra": "キャンベラ"
"Melbourne": "メルボルン"
"Sydney": "シドニー"
"Brisbane": "ブリスベン"
"Hobart": "ホバート"
"Vladivostok": "ウラジオストク"
"Guam": "グアム"
"Port Moresby": "ポートモレスビー"
"Magadan": "マガダン"
"Solomon Is": "ソロモン諸島"
"New Caledonia": "ニューカレドニア"
"Fiji": "フィジー"
"Kamchatka": "カムチャツカ半島"
"Marshall Is": "マーシャル諸島"
"Auckland": "オークランド"
"Wellington": "ウェリントン"
"Nuku'alofa": "ヌクアロファ"
"Tokelau Is": "トケラウ"