Skip to content

Commit b423aa0

Browse files
committed
Fix #22956 - make country names translatable
1 parent 2bc471e commit b423aa0

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,11 @@ protected function _sortOptionArray($option)
199199
public function getCountryTranslation($value, $locale = null)
200200
{
201201
if ($locale == null) {
202-
return (new RegionBundle())->get($this->localeResolver->getLocale())['Countries'][$value];
203-
} else {
204-
return (new RegionBundle())->get($locale)['Countries'][$value];
202+
$locale = $this->localeResolver->getLocale();
205203
}
204+
205+
$translation = (new RegionBundle())->get($locale)['Countries'][$value];
206+
207+
return $translation ? (string)__($translation) : $translation;
206208
}
207209
}

0 commit comments

Comments
 (0)