Created
June 29, 2016 18:00
-
-
Save osrecio/5222ef8a9235ed2ba56462b29c8cd88f to your computer and use it in GitHub Desktop.
Generate csv with all translations of Magento Project
This file contains hidden or 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
<?php | |
/** | |
* @category Interactiv4 | |
* @package Interactiv4 | |
* @copyright Copyright (c) 2016 Interactiv4 SL. (http://www.interactiv4.com) | |
* | |
*/ | |
$sourcePath = 'absolute_magento_root_path'; | |
$csvFile = 'mage_translate.csv'; | |
$searchExtensions = array('php', 'phtml'); | |
$strTranslateFunc = '->__'; | |
$arrItems = array(); | |
$di = new RecursiveDirectoryIterator($sourcePath); | |
foreach (new RecursiveIteratorIterator($di) as $filename => $file) { | |
if (in_array( strtolower( pathinfo($file, PATHINFO_EXTENSION) ), $searchExtensions)) | |
{ | |
$strContent = file_get_contents($filename); | |
$arrMatches = array(); | |
preg_match_all("/{$strTranslateFunc}\((?:(?:\"(?:\\\\\"|[^\"])+\")|(?:'(?:\\\'|[^'])+'))/is", $strContent, $arrMatches); | |
foreach($arrMatches as $matched) { | |
foreach($matched as $match) { | |
$_item = trim( str_replace("{$strTranslateFunc}(", '', $match) , "'\""); | |
if ( ! in_array($_item, $arrItems)) | |
{ | |
$arrItems[] = $_item; | |
} | |
} | |
} | |
} | |
} | |
$fp = fopen($csvFile, 'w'); | |
foreach ($arrItems as $_item) { | |
fputcsv($fp, array($_item, $_item)); | |
} | |
fclose($fp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment