Skip to content

Commit 519ff22

Browse files
ENGCOM-5663: Fix #22956 - make country names translatable #24179
- Merge Pull Request #24179 from Bartlomiejsz/magento2:feature/fix_22956_translate_country_names - Merged commits: 1. b423aa0 2. 23afffb 3. 8dab512
2 parents 8f911bb + 8dab512 commit 519ff22

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

lib/internal/Magento/Framework/Locale/Test/Unit/TranslatedListsTest.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,42 @@
66

77
namespace Magento\Framework\Locale\Test\Unit;
88

9-
class TranslatedListsTest extends \PHPUnit\Framework\TestCase
9+
use Magento\Framework\Locale\ConfigInterface;
10+
use Magento\Framework\Locale\ResolverInterface;
11+
use Magento\Framework\Locale\TranslatedLists;
12+
use PHPUnit\Framework\MockObject\MockObject;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class TranslatedListsTest extends TestCase
1016
{
1117
/**
12-
* @var \Magento\Framework\Locale\TranslatedLists
18+
* @var TranslatedLists
1319
*/
1420
protected $listsModel;
1521

1622
/**
17-
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Locale\ConfigInterface
23+
* @var MockObject | ConfigInterface
1824
*/
1925
protected $mockConfig;
2026

2127
/**
22-
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Locale\ResolverInterface
28+
* @var MockObject | ResolverInterface
2329
*/
2430
protected $mockLocaleResolver;
2531

2632
protected function setUp()
2733
{
28-
$this->mockConfig = $this->getMockBuilder(\Magento\Framework\Locale\ConfigInterface::class)
34+
$this->mockConfig = $this->getMockBuilder(ConfigInterface::class)
2935
->disableOriginalConstructor()
3036
->getMock();
31-
$this->mockLocaleResolver = $this->getMockBuilder(\Magento\Framework\Locale\ResolverInterface::class)
37+
$this->mockLocaleResolver = $this->getMockBuilder(ResolverInterface::class)
3238
->disableOriginalConstructor()
3339
->getMock();
3440
$this->mockLocaleResolver->expects($this->once())
3541
->method('getLocale')
36-
->will($this->returnValue('en_US'));
42+
->willReturn('en_US');
3743

38-
$this->listsModel = new \Magento\Framework\Locale\TranslatedLists(
44+
$this->listsModel = new TranslatedLists(
3945
$this->mockConfig,
4046
$this->mockLocaleResolver
4147
);
@@ -67,13 +73,13 @@ public function testGetOptionCurrencies()
6773

6874
$this->mockConfig->expects($this->once())
6975
->method('getAllowedCurrencies')
70-
->will($this->returnValue($allowedCurrencies));
76+
->willReturn($allowedCurrencies);
7177

7278
$expectedResults = ['USD', 'EUR', 'GBP', 'UAH'];
7379

7480
$currencyList = $this->listsModel->getOptionCurrencies();
7581
$currencyCodes = array_map(
76-
function ($data) {
82+
static function ($data) {
7783
return $data['value'];
7884
},
7985
$currencyList
@@ -166,6 +172,6 @@ protected function setupForOptionLocales()
166172
$allowedLocales = ['en_US', 'uk_UA', 'de_DE'];
167173
$this->mockConfig->expects($this->once())
168174
->method('getAllowedLocales')
169-
->will($this->returnValue($allowedLocales));
175+
->willReturn($allowedLocales);
170176
}
171177
}

lib/internal/Magento/Framework/Locale/TranslatedLists.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use Magento\Framework\Locale\Bundle\LanguageBundle;
1212
use Magento\Framework\Locale\Bundle\RegionBundle;
1313

14+
/**
15+
* Translated lists.
16+
*/
1417
class TranslatedLists implements ListsInterface
1518
{
1619
/**
@@ -176,6 +179,8 @@ public function getOptionAllCurrencies()
176179
}
177180

178181
/**
182+
* Sort option array.
183+
*
179184
* @param array $option
180185
* @return array
181186
*/
@@ -199,9 +204,11 @@ protected function _sortOptionArray($option)
199204
public function getCountryTranslation($value, $locale = null)
200205
{
201206
if ($locale == null) {
202-
return (new RegionBundle())->get($this->localeResolver->getLocale())['Countries'][$value];
203-
} else {
204-
return (new RegionBundle())->get($locale)['Countries'][$value];
207+
$locale = $this->localeResolver->getLocale();
205208
}
209+
210+
$translation = (new RegionBundle())->get($locale)['Countries'][$value];
211+
212+
return $translation ? (string)__($translation) : $translation;
206213
}
207214
}

0 commit comments

Comments
 (0)