Changeset 1564 for trunk/gregarius/dist

Show
Ignore:
Timestamp:
09/09/06 18:23:38 (2 years ago)
Author:
mbonetti
Message:

Localization works with most languages, now. Still missing language
selection routines, admin, ...

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/gregarius/dist/convert.php

    r1561 r1564  
    44    $EXCLUDE = '#(intl|extlib|dist)#'; 
    55 
    6     Convert('.'); 
    7  
     6    //Convert('.'); 
     7    buildPOs(); 
    88    function __callback__($matches) { 
    99        if (defined($matches[1])) { 
     
    1414    } 
    1515     
     16    function buildPOs() { 
     17        $files=array_keys(preg_find('/\.php$/','intl',PREG_FIND_RECURSIVE | PREG_FIND_FULLPATH|PREG_FIND_DIRONLY)); 
     18        if (($i=array_search('intl/en.php',$files)) !== FALSE) { 
     19            unset($files[$i]); 
     20        } 
     21        foreach($files as $file) { 
     22            echo "Now handling $file ..."; 
     23            $translations = array(); 
     24            $content = file_get_contents($file); 
     25            if(preg_match_all('#define\s*\([\'"](LOCALE_LINUX)[\'"][^,]*,\s*[\'"](.+)[\'"]\s*\);#',$content,$matches,PREG_SET_ORDER)) { 
     26                $locale = $matches[0][2]; 
     27                if (!file_exists("intl/$locale/LC_MESSAGES")) { 
     28                    mkdir("intl/$locale",0755); 
     29                    mkdir("intl/$locale/LC_MESSAGES",0755); 
     30                } 
     31                $fp = fopen("intl/$locale/LC_MESSAGES/messages.po",'w'); 
     32                if(!$fp) { 
     33                    echo "\tERROR, Couldn't create output file!\n"; 
     34                    continue; 
     35                } 
     36                $poheader='' 
     37.'# 
     38# 
     39msgid "" 
     40msgstr "" 
     41"Project-Id-Version: Gregarius 0.5.5\n" 
     42"Report-Msgid-Bugs-To: \n" 
     43"POT-Creation-Date: \n" 
     44"PO-Revision-Date: \n" 
     45"Last-Translator: \n" 
     46"Language-Team: \n" 
     47"MIME-Version: 1.0\n" 
     48"Content-Type: text/plain; charset=utf-8\n" 
     49"Content-Transfer-Encoding: 8bit\n" 
     50'; 
     51                fwrite($fp,$poheader."\n"); 
     52            } else { 
     53                echo "\tERROR, Unknown locale!\n"; 
     54                continue; 
     55            } 
     56             
     57            if (preg_match_all('#define\s*\([\'"](LBL_[^\'"]+)[\'"][^,]*,\s*[\'"](.+)[\'"]\s*\);#',$content,$matches,PREG_SET_ORDER)) { 
     58                foreach($matches as $match) { 
     59                    if (defined($match[1])) { 
     60                         
     61                        fwrite($fp,"#: $match[1]\n"); 
     62                        $en=str_replace('"','\"',stripslashes(stripslashes(constant($match[1])))); 
     63                        $intl=str_replace('"','\"',stripslashes(stripslashes($match[2]))); 
     64                        fwrite($fp,"msgid \"$en\"\n"); 
     65                        fwrite($fp,"msgstr \"$intl\"\n\n"); 
     66                    } 
     67                } 
     68                fwrite($fp,"#### END Automatic translation - ". date('r')." #\n"); 
     69                echo "\tdone!\n"; 
     70            } else { 
     71                echo "\tERROR, couldn't extract labels\n"; 
     72            } 
     73            if ($fp) { 
     74                @fclose($fp); 
     75            } 
     76        } 
     77    } 
    1678     
    1779    function Convert($dir)