Skip to content

Commit

Permalink
#8691: improved cases for DictionaryTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaha committed Jan 22, 2020
1 parent 0237c02 commit c42ebc1
Show file tree
Hide file tree
Showing 33 changed files with 267 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public function dictionaryDataProvider()
// Second case with inheritance of package with the same language code
'a case with inheritance similar language code' => $this->getDataInheritanceWitSimilarCode(),
// Third case with circular inheritance, when two packages depend on each other
'a case with circular inheritance' => $this->getDataCircularInheritance()
'a case with circular inheritance' => $this->getDataCircularInheritance(),
// Fourth case with multiple inheritance from dev docs
'a case with multiple inheritance from dev docs' => $this->getDataMultipleInheritanceFromDevDocs()
];
}

Expand Down Expand Up @@ -113,7 +115,7 @@ private function getDataCircularInheritance()
{
return [
// Dictionary that will be requested
'language_code' => 'en_US',
'language_code' => 'en_AZ',
// Expected merged dictionary data
'expectation' => [
'one' => '1.0',
Expand All @@ -123,4 +125,48 @@ private function getDataCircularInheritance()
]
];
}

/**
* If a language package inherits from two packages:
* ...
* <code>en_AK</code>
* ...
* <use vendor="parent-package-one" package="language_package_one"/>
* <use vendor= "parent-package-two" package="language_package_two"/>
* ...
*
* In the preceding example:
* language_package_one inherits from en_au_package and en_au_package inherits from en_ie_package
* language_package_two inherits from en_ca_package and en_ca_package inherits from en_us_package
*
* If the Magento application cannot find word or phrase in the en_AK package,
* it looks in other packages in following sequence:
* parent-package-one/language_package_one
* <vendorname>/en_au_package
* <vendorname>/en_ie_package
* parent-package-two/language_package_two
* <vendorname>/en_ca_package
* <vendorname>/en_us_package
*
* @return array
*/
private function getDataMultipleInheritanceFromDevDocs()
{
return [
// Dictionary that will be requested
'language_code' => 'en_AK',
// Expected merged dictionary data
'expectation' => [
'one' => 'en_us_package_one',
'two' => 'en_ca_package_two',
'three' => 'language_package_two_three',
'four' => 'en_ie_package_four',
'five' => 'en_au_package_five',
'six' => 'language_package_one_six',
'seven' => 'en_ak_seven',
'eight' => 'en_ak_eight',
'nine' => 'en_ak_nine',
]
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/
-->
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
<code>en_US</code>
<code>en_AZ</code>
<vendor>bar</vendor>
<package>en_us</package>
<package>en_az</package>
<sort_order>0</sort_order>
</language>
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'bar_en_us', __DIR__);
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'bar_en_az', __DIR__);
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
<vendor>bar</vendor>
<package>en_gb</package>
<sort_order>100</sort_order>
<use package="en_us" vendor="bar"/>
<use package="en_az" vendor="bar"/>
</language>
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
four and 5/10,4.5
one,1.00
two,2.00
three,3.00
four,4.00
four and 5/10,4.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
seven,en_ak_seven
eight,en_ak_eight
nine,en_ak_nine
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
<code>en_AK</code>
<vendor>devdoc</vendor>
<package>en_ak</package>
<sort_order>0</sort_order>
<use vendor="parent-package-one" package="language_package_one"/>
<use vendor="parent-package-two" package="language_package_two"/>
</language>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'devdoc_en_ak', __DIR__);
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/
-->
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
<code>en_US</code>
<code>en_AZ</code>
<vendor>first</vendor>
<package>en_us</package>
<package>en_az</package>
<sort_order>0</sort_order>
<use package="en_gb" vendor="second"/>
</language>
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'first_en_us', __DIR__);
ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'first_en_az', __DIR__);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
five,en_au_package_five
six,en_au_package_six
seven,en_au_package_seven
eight,en_au_package_eight
nine,en_au_package_nine
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
<code>en_US</code>
<vendor>parent-package-one</vendor>
<package>en_au_package</package>
<sort_order>0</sort_order>
<use vendor="parent-package-one" package="en_ie_package"/>
</language>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'parent-package-one_en_au_package', __DIR__);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
four,en_ie_package_four
five,en_ie_package_five
six,en_ie_package_six
seven,en_ie_package_seven
eight,en_ie_package_eight
nine,en_ie_package_nine
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
<code>en_US</code>
<vendor>parent-package-one</vendor>
<package>en_ie_package</package>
<sort_order>0</sort_order>
</language>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'parent-package-one_en_ie_package', __DIR__);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
six,language_package_one_six
seven,language_package_one_seven
eight,language_package_one_eight
nine,language_package_one_nine
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
<code>en_US</code>
<vendor>parent-package-one</vendor>
<package>language_package_one</package>
<sort_order>0</sort_order>
<use vendor="parent-package-one" package="en_au_package"/>
</language>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'parent-package-one_language_package_one', __DIR__);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
two,en_ca_package_two
three,en_ca_package_three
four,en_ca_package_four
five,en_ca_package_five
six,en_ca_package_six
seven,en_ca_package_seven
eight,en_ca_package_eight
nine,en_ca_package_nine
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
<code>en_US</code>
<vendor>parent-package-two</vendor>
<package>en_ca_package</package>
<sort_order>0</sort_order>
<use vendor="parent-package-two" package="en_us_package"/>
</language>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'parent-package-two_en_ca_package', __DIR__);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
one,en_us_package_one
two,en_us_package_two
three,en_us_package_three
four,en_us_package_four
five,en_us_package_five
six,en_us_package_six
seven,en_us_package_seven
eight,en_us_package_eight
nine,en_us_package_nine
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
<code>en_US</code>
<vendor>parent-package-two</vendor>
<package>en_us_package</package>
<sort_order>0</sort_order>
</language>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'parent-package-two_en_us_package', __DIR__);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
three,language_package_two_three
four,language_package_two_four
five,language_package_two_five
six,language_package_two_six
seven,language_package_two_seven
eight,language_package_two_eight
nine,language_package_two_nine
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/Language/package.xsd">
<code>en_US</code>
<vendor>parent-package-two</vendor>
<package>language_package_two</package>
<sort_order>0</sort_order>
<use vendor="parent-package-two" package="en_ca_package"/>
</language>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, 'parent-package-two_language_package_two', __DIR__);
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
<vendor>second</vendor>
<package>en_gb</package>
<sort_order>0</sort_order>
<use package="en_us" vendor="first"/>
<use package="en_az" vendor="first"/>
</language>
4 changes: 4 additions & 0 deletions lib/internal/Magento/Framework/App/Language/Dictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ private function collectInheritedPacks($languageConfig, &$result, $level = 0, ar
*/
private function addInheritedPacks($packs, $pack, &$sortedPacks)
{
if (isset($sortedPacks[$pack['key']])) {
return;
}

$sortedPacks[$pack['key']] = $pack;
foreach ($pack['language']->getUses() as $reuse) {
$packKey = implode('|', [$reuse['vendor'], $reuse['package']]);
Expand Down

0 comments on commit c42ebc1

Please sign in to comment.