Skip to content

Commit 328ebeb

Browse files
authored
ENGCOM-5972: Fix #12256 #13263 - add Serbian Latin language and change language lists to show script #22293
2 parents 8e09f0c + 9a29cc5 commit 328ebeb

File tree

6 files changed

+108
-68
lines changed

6 files changed

+108
-68
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ class Config implements \Magento\Framework\Locale\ConfigInterface
9191
'sk_SK', /*Slovak (Slovakia)*/
9292
'sl_SI', /*Slovenian (Slovenia)*/
9393
'sq_AL', /*Albanian (Albania)*/
94-
'sr_Cyrl_RS', /*Serbian (Serbia)*/
94+
'sr_Cyrl_RS', /*Serbian (Cyrillic, Serbia)*/
95+
'sr_Latn_RS', /*Serbian (Latin, Serbia)*/
9596
'sv_SE', /*Swedish (Sweden)*/
9697
'sv_FI', /*Swedish (Finland)*/
9798
'sw_KE', /*Swahili (Kenya)*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ConfigTest extends \PHPUnit\Framework\TestCase
1515
'es_MX', 'eu_ES', 'es_PE', 'et_EE', 'fa_IR', 'fi_FI', 'fil_PH', 'fr_CA', 'fr_FR', 'gu_IN',
1616
'he_IL', 'hi_IN', 'hr_HR', 'hu_HU', 'id_ID', 'is_IS', 'it_CH', 'it_IT', 'ja_JP', 'ka_GE',
1717
'km_KH', 'ko_KR', 'lo_LA', 'lt_LT', 'lv_LV', 'mk_MK', 'mn_Cyrl_MN', 'ms_Latn_MY', 'nl_NL', 'nb_NO',
18-
'nn_NO', 'pl_PL', 'pt_BR', 'pt_PT', 'ro_RO', 'ru_RU', 'sk_SK', 'sl_SI', 'sq_AL', 'sr_Cyrl_RS',
18+
'nn_NO', 'pl_PL', 'pt_BR', 'pt_PT', 'ro_RO', 'ru_RU', 'sk_SK', 'sl_SI', 'sq_AL', 'sr_Cyrl_RS', 'sr_Latn_RS',
1919
'sv_SE', 'sw_KE', 'th_TH', 'tr_TR', 'uk_UA', 'vi_VN', 'zh_Hans_CN', 'zh_Hant_HK', 'zh_Hant_TW', 'es_CL',
2020
'lo_LA', 'es_VE', 'en_IE',
2121
];

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

Lines changed: 65 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Framework\Locale\Test\Unit;
89

@@ -17,23 +18,62 @@ class TranslatedListsTest extends TestCase
1718
/**
1819
* @var TranslatedLists
1920
*/
20-
protected $listsModel;
21+
private $listsModel;
2122

2223
/**
23-
* @var MockObject | ConfigInterface
24+
* @var MockObject | ConfigInterface
2425
*/
25-
protected $mockConfig;
26+
private $mockConfig;
2627

2728
/**
28-
* @var MockObject | ResolverInterface
29+
* @var MockObject | ResolverInterface
2930
*/
30-
protected $mockLocaleResolver;
31+
private $mockLocaleResolver;
32+
33+
/**
34+
* @var array
35+
*/
36+
private $expectedCurrencies = [
37+
'USD',
38+
'EUR',
39+
'UAH',
40+
'GBP',
41+
];
42+
43+
/**
44+
* @var array
45+
*/
46+
private $expectedLocales = [
47+
'en_US' => 'English (United States)',
48+
'en_GB' => 'English (United Kingdom)',
49+
'uk_UA' => 'Ukrainian (Ukraine)',
50+
'de_DE' => 'German (Germany)',
51+
'sr_Cyrl_RS' => 'Serbian (Cyrillic, Serbia)',
52+
'sr_Latn_RS' => 'Serbian (Latin, Serbia)'
53+
];
54+
55+
/**
56+
* @var array
57+
*/
58+
private $expectedTranslatedLocales = [
59+
'en_US' => 'English (United States) / English (United States)',
60+
'en_GB' => 'English (United Kingdom) / English (United Kingdom)',
61+
'uk_UA' => 'українська (Україна) / Ukrainian (Ukraine)',
62+
'de_DE' => 'Deutsch (Deutschland) / German (Germany)',
63+
'sr_Cyrl_RS' => 'српски (ћирилица, Србија) / Serbian (Cyrillic, Serbia)',
64+
'sr_Latn_RS' => 'Srpski (latinica, Srbija) / Serbian (Latin, Serbia)'
65+
];
3166

3267
protected function setUp()
3368
{
3469
$this->mockConfig = $this->getMockBuilder(ConfigInterface::class)
3570
->disableOriginalConstructor()
3671
->getMock();
72+
$this->mockConfig->method('getAllowedLocales')
73+
->willReturn(array_keys($this->expectedLocales));
74+
$this->mockConfig->method('getAllowedCurrencies')
75+
->willReturn($this->expectedCurrencies);
76+
3777
$this->mockLocaleResolver = $this->getMockBuilder(ResolverInterface::class)
3878
->disableOriginalConstructor()
3979
->getMock();
@@ -69,12 +109,6 @@ public function testGetOptionAllCurrencies()
69109

70110
public function testGetOptionCurrencies()
71111
{
72-
$allowedCurrencies = ['USD', 'EUR', 'GBP', 'UAH'];
73-
74-
$this->mockConfig->expects($this->once())
75-
->method('getAllowedCurrencies')
76-
->willReturn($allowedCurrencies);
77-
78112
$expectedResults = ['USD', 'EUR', 'GBP', 'UAH'];
79113

80114
$currencyList = $this->listsModel->getOptionCurrencies();
@@ -134,44 +168,34 @@ public function testGetOptionTimezones()
134168

135169
public function testGetOptionLocales()
136170
{
137-
$this->setupForOptionLocales();
138-
139-
$expectedResults = ['en_US', 'uk_UA', 'de_DE'];
140-
141-
$list = $this->listsModel->getOptionLocales();
142-
foreach ($expectedResults as $value) {
143-
$found = false;
144-
foreach ($list as $item) {
145-
$found = $found || ($value == $item['value']);
146-
}
147-
$this->assertTrue($found);
148-
}
171+
$locales = array_intersect(
172+
$this->expectedLocales,
173+
$this->convertOptionLocales($this->listsModel->getOptionLocales())
174+
);
175+
$this->assertEquals($this->expectedLocales, $locales);
149176
}
150177

151178
public function testGetTranslatedOptionLocales()
152179
{
153-
$this->setupForOptionLocales();
154-
155-
$expectedResults = ['en_US', 'uk_UA', 'de_DE'];
156-
157-
$list = $this->listsModel->getOptionLocales();
158-
foreach ($expectedResults as $value) {
159-
$found = false;
160-
foreach ($list as $item) {
161-
$found = $found || ($value == $item['value']);
162-
}
163-
$this->assertTrue($found);
164-
}
180+
$locales = array_intersect(
181+
$this->expectedTranslatedLocales,
182+
$this->convertOptionLocales($this->listsModel->getTranslatedOptionLocales())
183+
);
184+
$this->assertEquals($this->expectedTranslatedLocales, $locales);
165185
}
166186

167187
/**
168-
* Setup for option locales
188+
* @param array $optionLocales
189+
* @return array
169190
*/
170-
protected function setupForOptionLocales()
191+
private function convertOptionLocales($optionLocales): array
171192
{
172-
$allowedLocales = ['en_US', 'uk_UA', 'de_DE'];
173-
$this->mockConfig->expects($this->once())
174-
->method('getAllowedLocales')
175-
->willReturn($allowedLocales);
193+
$result = [];
194+
195+
foreach ($optionLocales as $optionLocale) {
196+
$result[$optionLocale['value']] = $optionLocale['label'];
197+
}
198+
199+
return $result;
176200
}
177201
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,23 @@ protected function _getOptionLocales($translatedName = false)
8181
}
8282
$language = \Locale::getPrimaryLanguage($locale);
8383
$country = \Locale::getRegion($locale);
84+
$script = \Locale::getScript($locale);
85+
$scriptTranslated = '';
8486
if (!$languages[$language] || !$countries[$country]) {
8587
continue;
8688
}
89+
if ($script !== '') {
90+
$script = \Locale::getDisplayScript($locale) . ', ';
91+
$scriptTranslated = \Locale::getDisplayScript($locale, $locale) . ', ';
92+
}
8793
if ($translatedName) {
8894
$label = ucwords(\Locale::getDisplayLanguage($locale, $locale))
89-
. ' (' . \Locale::getDisplayRegion($locale, $locale) . ') / '
95+
. ' (' . $scriptTranslated . \Locale::getDisplayRegion($locale, $locale) . ') / '
9096
. $languages[$language]
91-
. ' (' . $countries[$country] . ')';
97+
. ' (' . $script . $countries[$country] . ')';
9298
} else {
9399
$label = $languages[$language]
94-
. ' (' . $countries[$country] . ')';
100+
. ' (' . $script . $countries[$country] . ')';
95101
}
96102
$options[] = ['value' => $locale, 'label' => $label];
97103
}

lib/internal/Magento/Framework/Setup/Lists.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Framework\Setup;
89

@@ -12,6 +13,9 @@
1213
use Magento\Framework\Locale\ConfigInterface;
1314
use Magento\Framework\Locale\Resolver;
1415

16+
/**
17+
* Retrieves lists of allowed locales and currencies
18+
*/
1519
class Lists
1620
{
1721
/**
@@ -99,10 +103,14 @@ public function getLocaleList()
99103
}
100104
$language = \Locale::getPrimaryLanguage($locale);
101105
$country = \Locale::getRegion($locale);
106+
$script = \Locale::getScript($locale);
102107
if (!$languages[$language] || !$countries[$country]) {
103108
continue;
104109
}
105-
$list[$locale] = $languages[$language] . ' (' . $countries[$country] . ')';
110+
if ($script !== '') {
111+
$script = \Locale::getDisplayScript($locale) . ', ';
112+
}
113+
$list[$locale] = $languages[$language] . ' (' . $script . $countries[$country] . ')';
106114
}
107115
asort($list);
108116
return $list;

lib/internal/Magento/Framework/Setup/Test/Unit/ListsTest.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,31 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Framework\Setup\Test\Unit;
89

10+
use Magento\Framework\Locale\ConfigInterface;
911
use Magento\Framework\Setup\Lists;
12+
use PHPUnit\Framework\TestCase;
13+
use PHPUnit\Framework\MockObject\MockObject;
1014

11-
class ListsTest extends \PHPUnit\Framework\TestCase
15+
class ListsTest extends TestCase
1216
{
1317
/**
1418
* @var Lists
1519
*/
16-
protected $lists;
20+
private $lists;
1721

1822
/**
19-
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Locale\ConfigInterface
23+
* @var MockObject|ConfigInterface
2024
*/
21-
protected $mockConfig;
25+
private $mockConfig;
2226

2327
/**
2428
* @var array
2529
*/
26-
protected $expectedTimezones = [
30+
private $expectedTimezones = [
2731
'Australia/Darwin',
2832
'America/Los_Angeles',
2933
'Europe/Kiev',
@@ -33,7 +37,7 @@ class ListsTest extends \PHPUnit\Framework\TestCase
3337
/**
3438
* @var array
3539
*/
36-
protected $expectedCurrencies = [
40+
private $expectedCurrencies = [
3741
'USD',
3842
'EUR',
3943
'UAH',
@@ -43,23 +47,23 @@ class ListsTest extends \PHPUnit\Framework\TestCase
4347
/**
4448
* @var array
4549
*/
46-
protected $expectedLocales = [
47-
'en_US',
48-
'en_GB',
49-
'uk_UA',
50-
'de_DE',
50+
private $expectedLocales = [
51+
'en_US' => 'English (United States)',
52+
'en_GB' => 'English (United Kingdom)',
53+
'uk_UA' => 'Ukrainian (Ukraine)',
54+
'de_DE' => 'German (Germany)',
55+
'sr_Cyrl_RS' => 'Serbian (Cyrillic, Serbia)',
56+
'sr_Latn_RS' => 'Serbian (Latin, Serbia)'
5157
];
5258

5359
protected function setUp()
5460
{
55-
$this->mockConfig = $this->getMockBuilder(\Magento\Framework\Locale\ConfigInterface::class)
61+
$this->mockConfig = $this->getMockBuilder(ConfigInterface::class)
5662
->disableOriginalConstructor()
5763
->getMock();
58-
$this->mockConfig->expects($this->any())
59-
->method('getAllowedLocales')
60-
->willReturn($this->expectedLocales);
61-
$this->mockConfig->expects($this->any())
62-
->method('getAllowedCurrencies')
64+
$this->mockConfig->method('getAllowedLocales')
65+
->willReturn(array_keys($this->expectedLocales));
66+
$this->mockConfig->method('getAllowedCurrencies')
6367
->willReturn($this->expectedCurrencies);
6468

6569
$this->lists = new Lists($this->mockConfig);
@@ -73,13 +77,10 @@ public function testGetTimezoneList()
7377

7478
public function testGetLocaleList()
7579
{
76-
$locales = array_intersect($this->expectedLocales, array_keys($this->lists->getLocaleList()));
80+
$locales = array_intersect($this->expectedLocales, $this->lists->getLocaleList());
7781
$this->assertEquals($this->expectedLocales, $locales);
7882
}
7983

80-
/**
81-
* Test Lists:getCurrencyList() considering allowed currencies config values.
82-
*/
8384
public function testGetCurrencyList()
8485
{
8586
$currencies = array_intersect($this->expectedCurrencies, array_keys($this->lists->getCurrencyList()));

0 commit comments

Comments
 (0)