Forked from robbanl/TranslateMagentoModule.php
Last active
September 18, 2016 19:48
-
-
Save riversy/ee9dbec3f849cefe83779a4a0f712bdc to your computer and use it in GitHub Desktop.
Get translatable strings for Magento modules
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 | |
/** | |
* Get translatable strings for Magento modules | |
* | |
* Tested on Mac & Linux | |
* | |
* Usage: | |
* | |
* 1. Change the $path variable to where your module is located | |
* 2. php TranslateMagentoModule.php | |
* | |
* To save the result without copy-paste run php TranslateMagentoModule.php > /path/to/locale/myLanguageFile.csv | |
*/ | |
// Surpress errors | |
error_reporting(0); | |
ini_set('display_errors', 'off'); | |
// Where the module is located | |
$paths = [ | |
'/path1/', | |
'/path2/', | |
]; | |
// Setup the search patterns | |
$patterns = array( | |
'/__\(\'(.*)\'\)/i', | |
'/__\("(.*)"\)/i' | |
); | |
$csv = array(); | |
// Loop through all files | |
foreach ( $paths as $path ){ | |
// Get a list of all PHP files in that directory | |
@exec('find ' . $path . ' | grep php', $fileList); | |
// Setup data storage arrayu | |
foreach ( $fileList as $file ) | |
{ | |
// Open the file | |
$data = file_get_contents($file); | |
// Make sure we've got some data | |
if ( $data ) | |
{ | |
// Process each pattern | |
foreach ( $patterns as $pattern ) | |
{ | |
// Match all __('') strings | |
preg_match_all($pattern, $data, $matches); | |
// Check if we've got some results | |
if ( count($matches[1]) > 0 ) { | |
// Loop through the result | |
foreach ( $matches[1] as $match ) { | |
// Add line to csv array | |
$csv[] = '"' . $match . '","' . $match . '"'; | |
} | |
} | |
} | |
} | |
} | |
} | |
// Make lines unique | |
$csv = array_unique($csv); | |
// Return the output | |
print implode("\n", $csv); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment