-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved calculating version hash for the js-translation.json file. #10378
Merged
magento-team
merged 9 commits into
magento:develop
from
hostep:improve-translation-version-hash
Aug 18, 2017
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a1dab12
Improved calculating version hash for the js-translation.json file.
hostep b3a1c7e
Refactored getting translation file version into a more desirable sta…
hostep 507cd42
Start using the file contents for calculating the hash again instead …
hostep def3cff
Fixes integration tests.
hostep 75990d4
magento/magento2#10378: Merge branch 'develop' of github.com:magento/…
ishakhsuvarov cc44db7
magento/magento2#10378: Merge branch 'develop' of github.com:magento/…
ishakhsuvarov 93ca363
magento/magento2#10378: Improved calculating version hash for the js-…
ishakhsuvarov 5b1b749
magento/magento2#10378: Merge branch 'develop' of github.com:magento/…
ishakhsuvarov cbca085
magento/magento2#10378: Improved calculating version hash for the js-…
ishakhsuvarov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Translation\Model\Inline; | ||
|
||
use Magento\Framework\Translate\ResourceInterface; | ||
use Magento\Framework\Locale\ResolverInterface; | ||
use Magento\Framework\Serialize\Serializer\Json; | ||
|
||
/** | ||
* Prepares content of inline translations file. | ||
*/ | ||
class File | ||
{ | ||
/** | ||
* @var ResourceInterface | ||
*/ | ||
private $translateResource; | ||
|
||
/** | ||
* @var ResolverInterface | ||
*/ | ||
private $localeResolver; | ||
|
||
/** | ||
* @var Json | ||
*/ | ||
private $jsonSerializer; | ||
|
||
/** | ||
* Initialize dependencies | ||
* | ||
* @param ResourceInterface $translateResource | ||
* @param ResolverInterface $localeResolver | ||
* @param Json $jsonSerializer | ||
*/ | ||
public function __construct( | ||
ResourceInterface $translateResource, | ||
ResolverInterface $localeResolver, | ||
Json $jsonSerializer | ||
) { | ||
$this->translateResource = $translateResource; | ||
$this->localeResolver = $localeResolver; | ||
$this->jsonSerializer = $jsonSerializer; | ||
} | ||
|
||
/** | ||
* Generate translation file content for the current locale. | ||
* | ||
* @return string | ||
*/ | ||
public function getTranslationFileContent() | ||
{ | ||
$translations = $this->translateResource->getTranslationArray(null, $this->localeResolver->getLocale()); | ||
$translations = $this->jsonSerializer->serialize($translations); | ||
return $translations; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/code/Magento/Translation/Test/Unit/Model/Inline/FileTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Translation\Test\Unit\Model\Inline; | ||
|
||
class FileTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var \Magento\Translation\Model\Inline\File | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var \Magento\Framework\Translate\ResourceInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $translateResourceMock; | ||
|
||
/** | ||
* @var \Magento\Framework\Locale\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $localeResolverMock; | ||
|
||
/** | ||
* @var \Magento\Framework\Serialize\Serializer\Json | ||
*/ | ||
private $jsonSerializer; | ||
|
||
protected function setUp() | ||
{ | ||
$this->translateResourceMock = $this->getMockBuilder(\Magento\Framework\Translate\ResourceInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->localeResolverMock = $this->getMockBuilder(\Magento\Framework\Locale\ResolverInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->jsonSerializer = new \Magento\Framework\Serialize\Serializer\Json(); | ||
|
||
$this->model = new \Magento\Translation\Model\Inline\File( | ||
$this->translateResourceMock, | ||
$this->localeResolverMock, | ||
$this->jsonSerializer | ||
); | ||
} | ||
|
||
public function testGetTranslationFileContent() | ||
{ | ||
$translations = ['string' => 'translatedString']; | ||
|
||
$this->localeResolverMock->expects($this->atLeastOnce())->method('getLocale')->willReturn('en_US'); | ||
$this->translateResourceMock->expects($this->atLeastOnce())->method('getTranslationArray') | ||
->willReturn($translations); | ||
|
||
$this->assertEquals( | ||
$this->jsonSerializer->serialize($translations), | ||
$this->model->getTranslationFileContent() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shoudn't we escape version there? Previously it was always sha1, but from now it uses raw value from public method, that could be overridden by plugin.
@ishakhsuvarov i think it should be escaped. what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds completely reasonable to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ishakhsuvarov pull request prepared #10904