Opened 12 years ago

Closed 12 years ago

#203 closed defect (fixed)

_lc(...) language .js scanner

Reported by: kim@… Owned by: niko
Priority: normal Milestone:
Component: Language Version: trunk
Severity: normal Keywords:
Cc:

Description

I put together a little PHP script that scans through the plugin folder and parses all the .js files for _lc(...) entries and generate a report. This can be usefull for tracking changes in the plugins for new language strings. The catch for this to work is that all entries are present in the .js files and that it matches _lc("...")

The php file should be stored in the plugins folder, and is ready to run - no configuring is needed.

Filename : lc_strings_report.php

<?php
/* Quick system for analyzing the files for _lc occurencies. 
   All pluginfolders are scanned for .js files, and the .js  
   files are then parsed for _lc() occurencies and listed.   
                                                             
   Credits : Kim Steinhaug, kim@steinhaug.com                
   Version v1.0                                              
                                                           */

function retrieveDirs($rootdirpath,$eregi_match='') {
 if ($dir = @opendir($rootdirpath)) {
   $array = array();
   while (($file = readdir($dir)) !== false) {
     if (is_dir($rootdirpath."/".$file) && $file != "." && $file != "..") {
       if(!$eregi_match){
	     $array[] = $file;
	   } else {
         if(eregi($eregi_match,$file))
		 $array[] = $file;
	   }
    } else if($eregi_match && $file != "." && $file != ".."){
      if(eregi($eregi_match,$file))
      $array[] = $file;
	}
   }
   closedir($dir);
 }
 return $array;
}

function get_lc_array($data){
  $temp = explode('_lc(',$data);
  $return = array();
  foreach ($temp AS $value){ 
    if(substr($value,0,6)=='string'){
	} else if(substr($value,0,1)=='"'){
      $temp2 = explode('")',$value);
      $var = substr($temp2[0],1);
      if(ereg('"',$var)){
	    $temp3 = explode('"',$var);
        $var = $temp3[0];
      } else {
	  }
	  array_push($return,$var);
	}
  }
  return $return;
}

echo '<em>Brief explernation, scans through all folders and parses all .js files for _lc(...) entries and lists them.</em>';

$path = str_replace('lc_strings_report.php','',$_SERVER["SCRIPT_FILENAME"]);
$dirs = retrieveDirs($path);
foreach ($dirs AS $dir){ 
  echo '<h3>' . $dir . '</h3>';
  $jsfiles = retrieveDirs($path . '/' . $dir . '/','js');
  if(is_array($jsfiles) && count($jsfiles)){
    foreach ($jsfiles AS $filename){ 
      $data = file_get_contents($path . '/' . $dir . '/' . $filename);
      $lc = get_lc_array($data);
      foreach ($lc AS $lc_var){ 
        echo '&nbsp; &nbsp; &quot;' . $lc_var . '&quot;' . "<br>\r\n";
      }
    }
  }
}

?>

Attachments (2)

lc_strings_report.php (2.1 KB) - added by kim@… 12 years ago.
lc_strings_report.php
lc_parse_strings.php (6.4 KB) - added by niko 12 years ago.
php-script that parses all source-files wor l10n-strings and writes a lang/base.js

Download all attachments as: .zip

Change History (14)

Changed 12 years ago by kim@…

lc_strings_report.php

comment:1 Changed 12 years ago by niko

thanks for that!
i will test it soon!

(and please view my last post in #158)

comment:2 Changed 12 years ago by niko

after a quick test it showed that your script doesn't scan htmlarea.js, so i added in line 54 $dirs[] = "./"

additional it would be nice to scan all plugins too.
and a needed feature is to output it in the format as the language-files are written, say

{
  "foo": "foo",
  "bar": "bar"
}

comment:3 Changed 12 years ago by Paul Baranowski <paul@…>

  • Component changed from Plugin - Fullscreen to Xinha Core

Great script! There is one nagging problem however. The popups do not use HTMLArea.lc() to translate their strings, and so they will not be picked up.

comment:4 Changed 12 years ago by niko

(posted this allready in #158, but since this ticket doesn't have anything to do with this topic and it is allready closed i post it here again:

the popups are planned to be changed into a system much like the linker-plugin uses.
http://xinha.gogo.co.nz/punbb/viewtopic.php?id=163
when this is finished we only have to this:

  • scan all *.js for ._lc
  • scan all *.html for <l10n>blah<l10n> (currently only plugins/Linker/dialog.html)
  • scan all *.html for _(blah) (currently only plugins/Linker/dialog.html)

in htmlara.js line 363 best would be to add the _lc-call directly here, not in line 455

comment:5 Changed 12 years ago by niko

(..i don't get the wiki-sytax :D so here the list again for easier reading:)

  • scan all *.js for ._lc
  • scan all *.html for <l10n>blah<l10n> (currently only plugins/Linker/dialog.html)
  • scan all *.html for _(blah) (currently only plugins/Linker/dialog.html)

comment:6 Changed 12 years ago by gogo

  • Owner changed from gogo to niko

comment:7 Changed 12 years ago by gogo

  • Component changed from Xinha Core to Language
  • Version set to trunk

Changed 12 years ago by niko

php-script that parses all source-files wor l10n-strings and writes a lang/base.js

comment:8 Changed 12 years ago by niko

I just uploaded a new l10n-parse-script that finds (hopefully) all used strings.
Just put it into the xinha-folder and start it in your web-browser.
lang/base.js files will be created which can be used as base for all i18n-files.

comment:9 Changed 12 years ago by niko

...there might be strings used somewhere that won't be found by my script.... if you find one post it here! (the same for found but not used strings of course)

comment:10 Changed 12 years ago by anonymous

# scan all *.js for ._lc
# scan all *.html for <l10n>blah<l10n> (currently only plugins/Linker/dialog.html)
# scan all *.html for _(blah) (currently only plugins/Linker/dialog.html)

what about the plugins that are using php files and not html files like ImageManager ?

comment:11 Changed 12 years ago by niko

it actually does scan .php files too. for ImageManager it finds 63 strings - i haven't checked if these are all - one would have to do a translation then we could check that.

comment:12 Changed 12 years ago by niko

  • Resolution set to fixed
  • Status changed from new to closed

i commited the script in changeset:288

Note: See TracTickets for help on using tickets.