From c332230709894e50fe1b5fc916adf3e6bb81fcc7 Mon Sep 17 00:00:00 2001 From: songtianlun Date: Tue, 28 Jan 2025 01:49:13 +0800 Subject: [PATCH] feat: enhance city localization and timezone handling - Update localized_name method to provide a default value for missing translations - Modify timezone display in city show view to show a message when the timezone is undefined These changes improve user experience by ensuring that the city localization falls back to the city name itself if a translation is not found, and they handle potentially missing timezone data more gracefully. --- app/models/city.rb | 2 +- app/views/cities/show.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/city.rb b/app/models/city.rb index 38461e1..95f8f4d 100644 --- a/app/models/city.rb +++ b/app/models/city.rb @@ -84,7 +84,7 @@ class City < ApplicationRecord end def localized_name - I18n.t("cities.#{name.parameterize.underscore}") + I18n.t("cities.#{name.parameterize.underscore}", default: name) end def full_name diff --git a/app/views/cities/show.html.erb b/app/views/cities/show.html.erb index 55f6353..c709d87 100644 --- a/app/views/cities/show.html.erb +++ b/app/views/cities/show.html.erb @@ -35,7 +35,7 @@ <%= @city.country.name %>, <%= @city.region %>
- <%= Time.current.in_time_zone(@city.timezone).strftime("%Y-%m-%d %H:%M") %> + <%= @city.timezone.present? ? Time.current.in_time_zone(@city.timezone).strftime("%Y-%m-%d %H:%M") : "Timezone undefined" %>