Skip to content
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

Missing strings for Javascript Translations #1447

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions app/code/Magento/Translation/Model/Js/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,17 @@ public function __construct(State $appState, Config $config, Filesystem $filesys
public function getData($themePath)
{
$dictionary = [];
$areaCode = $this->appState->getAreaCode();

$files = $this->filesUtility->getJsFiles($areaCode, $themePath);
$staticHtmlFiles = $this->filesUtility->getStaticHtmlFiles($areaCode, $themePath);

if (is_array($staticHtmlFiles)) {
foreach ($staticHtmlFiles as $staticFile) {
$files[] = $staticFile;
}
}

$files = $this->filesUtility->getJsFiles($this->appState->getAreaCode(), $themePath);
foreach ($files as $filePath) {
$content = $this->rootDirectory->readFile($this->rootDirectory->getRelativePath($filePath[0]));
foreach ($this->getPhrases($content) as $phrase) {
Expand Down Expand Up @@ -99,7 +108,11 @@ protected function getPhrases($content)
$result = preg_match_all($pattern, $content, $matches);

if ($result) {
$phrases = array_merge($phrases, $matches[1]);
if (isset($matches[1])) {
foreach ($matches[1] as $match) {
$phrases[] = $match;
}
}
}
if (false === $result) {
throw new \Exception(
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Translation/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<arguments>
<argument name="patterns" xsi:type="array">
<item name="mage_translation_widget" xsi:type="string">~\$\.mage\.__\([\'|\"](.+?)[\'|\"]\)~</item>
<item name="mage_translation_static" xsi:type="string">~\$t\([\'|\"](.+?)[\'|\"]\)~</item>
</argument>
</arguments>
</type>
Expand Down
28 changes: 28 additions & 0 deletions lib/internal/Magento/Framework/App/Utility/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,34 @@ public function getJsFiles($area = '*', $themePath = '*/*', $namespace = '*', $m
return $result;
}

/**
* Returns list of Static HTML files in Magento
*
* @param string $area
* @param string $themePath
* @param string $namespace
* @param string $module
* @return array
*/
public function getStaticHtmlFiles($area = '*', $themePath = '*/*', $namespace = '*', $module = '*')
{
$key = $area . $themePath . $namespace . $module . __METHOD__ . $this->_path;
if (isset(self::$_cache[$key])) {
return self::$_cache[$key];
}
$files = self::getFiles(
[
"{$this->_path}/app/code/{$namespace}/{$module}/view/{$area}/web/template",
"{$this->_path}/app/design/{$area}/{$themePath}/web/template",
"{$this->_path}/app/design/{$area}/{$themePath}/{$module}/web/template"
],
'*.html'
);
$result = self::composeDataSets($files);
self::$_cache[$key] = $result;
return $result;
}

/**
* Get list of static view files that are subject of Magento static view files preprocessing system
*
Expand Down