How to Get all Translation Labels from PHP and JS files of Magento 2 Extension

To write a generator label function with XML file using:

File directory: xampp/htdocs/translation/translatelabel.php

The following steps are the shortest process for you to get all translation labels from PHP and JS files of Magento 2 Extension.

  $searchExtensions = array('xml', 'xml');

  $strTranslateFunc = 'title=';

  $arrItems = array(); 

  $sourcePath = 'your_folder_source'; 

  $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}\"(.+?)\"|\/{$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);

By using these steps you can easily handle the translation labels from PHP and JS files of Magento 2 Extension.Each store has a translate labels from PHP and JS files of Magento 2 with many features.

Last Update: April 4, 2018  

February 2, 2018   135   Nandini R    Java Script    
Total 2 Votes:
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
Google+
http://www.webnexs.com/blog/kb/get-translation-labels-php-js-files-magento-2-extension
Twitter
LinkedIn