Skip to content

Instantly share code, notes, and snippets.

@osrecio
Created June 29, 2016 18:00
Show Gist options
  • Save osrecio/5222ef8a9235ed2ba56462b29c8cd88f to your computer and use it in GitHub Desktop.
Save osrecio/5222ef8a9235ed2ba56462b29c8cd88f to your computer and use it in GitHub Desktop.
Generate csv with all translations of Magento Project
<?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