From 2d61bed49a18cadef3c38b58b85089b53cee9e70 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Mon, 26 Aug 2024 11:01:17 -0400 Subject: [PATCH] Return the country in the current app locale --- CHANGELOG-WIP.md | 3 +++ src/elements/Address.php | 2 +- src/fields/Country.php | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG-WIP.md b/CHANGELOG-WIP.md index 133039a0bd1..35f28cf3cbf 100644 --- a/CHANGELOG-WIP.md +++ b/CHANGELOG-WIP.md @@ -1,5 +1,8 @@ # Release Notes for Craft CMS 4.12 (WIP) +### Development +- Country field values and `craft\elements\Address::getCountry()` now return the country in the current application locale. + ### Extensibility - Added `craft\base\ApplicationTrait::getEnvId()`. ([#15313](https://github.com/craftcms/cms/issues/15313)) - Added `craft\base\ElementInterface::getRootOwner()`. ([#15534](https://github.com/craftcms/cms/discussions/15534)) diff --git a/src/elements/Address.php b/src/elements/Address.php index 39a37689ec6..9726012ee6d 100644 --- a/src/elements/Address.php +++ b/src/elements/Address.php @@ -416,7 +416,7 @@ public function getCountryCode(): string */ public function getCountry(): Country { - return Craft::$app->getAddresses()->getCountryRepository()->get($this->countryCode); + return Craft::$app->getAddresses()->getCountryRepository()->get($this->countryCode, Craft::$app->language); } /** diff --git a/src/fields/Country.php b/src/fields/Country.php index ab6e57f7c87..818e457865e 100644 --- a/src/fields/Country.php +++ b/src/fields/Country.php @@ -54,7 +54,7 @@ public function normalizeValue(mixed $value, ElementInterface $element = null): } try { - return Craft::$app->getAddresses()->getCountryRepository()->get($value); + return Craft::$app->getAddresses()->getCountryRepository()->get($value, Craft::$app->language); } catch (UnknownCountryException) { return null; }