Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Localize country name in admin address display (#14224)
Damian Legawiec2d564dcdaffe
diff --git a/packages/dashboard-ui/src/spree/address-block.tsx b/packages/dashboard-ui/src/spree/address-block.tsxindex 14b18d90af..5ae3b08022 100644--- a/packages/dashboard-ui/src/spree/address-block.tsx+++ b/packages/dashboard-ui/src/spree/address-block.tsx@@ -13,10 +13,32 @@ export interface AddressBlockValue {city?: string | nullstate_text?: string | nullpostal_code?: string | null+ country_iso?: string | nullcountry_name?: string | nullphone?: string | null}+/**+ * Resolves a country name localized to the admin UI language via+ * `Intl.DisplayNames`, falling back to the API-provided name (then the ISO+ * code) when the ISO is missing or the runtime lacks coverage.+ */+function localizedCountryName(+ locale: string,+ iso?: string | null,+ name?: string | null,+): string | null {+ if (iso) {+ try {+ const localized = new Intl.DisplayNames([locale, 'en'], { type: 'region' }).of(iso)+ if (localized) return localized+ } catch {+ // Runtime without Intl.DisplayNames coverage — fall back below.+ }+ }+ return name ?? iso ?? null+}+export function AddressBlock({title,address,@@ -24,7 +46,7 @@ export function AddressBlock({title: stringaddress: AddressBlockValue | null | undefined}) {- const { t } = useTranslation()+ const { t, i18n } = useTranslation()return (<div><h6 className="font-semibold text-sm mb-1.5">{title}</h6>@@ -37,7 +59,9 @@ export function AddressBlock({<div>{[address.city, address.state_text, address.postal_code].filter(Boolean).join(', ')}</div>- <div>{address.country_name}</div>+ <div>+ {localizedCountryName(i18n.language, address.country_iso, address.country_name)}+ </div>{address.phone && <div>{address.phone}</div>}</div>) : (diff --git a/spree/admin/app/views/spree/admin/shared/_address.html.erb b/spree/admin/app/views/spree/admin/shared/_address.html.erbindex 1c40824fe9..8c7e2b6af1 100644--- a/spree/admin/app/views/spree/admin/shared/_address.html.erb+++ b/spree/admin/app/views/spree/admin/shared/_address.html.erb@@ -23,7 +23,7 @@<span class="locality"><%= address.city %></span><span class="region"><%= address.state_text %></span><span class="postal-code"><%= address.zipcode %></span>- <div class="country-name"><%= address.country.try(:name) %></div>+ <div class="country-name"><%= localized_country_name(address.country) if address.country %></div></div></div><% unless address.phone.blank? %>