Skip to content

Instantly share code, notes, and snippets.

@webdawe
Created August 26, 2016 04:29
Show Gist options
  • Save webdawe/c4eff50173a6e4f041032d724e01d5c7 to your computer and use it in GitHub Desktop.
Save webdawe/c4eff50173a6e4f041032d724e01d5c7 to your computer and use it in GitHub Desktop.
Get All the Strings to get Translated
<?php
/**
* Author : Anil Paul
* Date: 25/08/16
* Time: 5:19 PM
*/
$sourcePath = 'Module Path';
$csvFile = 'Namespace_Module.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