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.
This commit is contained in:
songtianlun 2025-01-28 01:49:13 +08:00
parent f0f94de528
commit c332230709
2 changed files with 2 additions and 2 deletions

View File

@ -84,7 +84,7 @@ class City < ApplicationRecord
end end
def localized_name def localized_name
I18n.t("cities.#{name.parameterize.underscore}") I18n.t("cities.#{name.parameterize.underscore}", default: name)
end end
def full_name def full_name

View File

@ -35,7 +35,7 @@
<%= @city.country.name %>, <%= @city.region %> <%= @city.country.name %>, <%= @city.region %>
</div> </div>
<div class="badge badge-lg badge-secondary gap-2"> <div class="badge badge-lg badge-secondary gap-2">
<%= 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" %>
</div> </div>
</div> </div>