Skip to content

Instantly share code, notes, and snippets.

@mikelietz
Created June 7, 2012 15:15
Show Gist options
  • Select an option

  • Save mikelietz/2889343 to your computer and use it in GitHub Desktop.

Select an option

Save mikelietz/2889343 to your computer and use it in GitHub Desktop.
filename:linenumber locale generator for Habari
<?php
$infile = "habari.pot";
$outfile = "habari.po";
$in = fopen( $infile, "r" );
$out = fopen( $outfile, "w" );
$buffer = "";
while( ($line = fgets($in)) !== false ) {
if ( substr($line,0,1) == '#' || substr($line,0,1) == '"' )
$buffer .= $line;
if ( substr($line,0,5) == 'msgid' ) {
$buffer .= $line;
// $msgtext = substr( $line, 7, -2 ) . "\n";
$next_line = fgets($in);
if ( substr($next_line,0,6) == 'msgstr' ) {
preg_match_all('%(((?:\w+/)+)?([\w\.]+\.\w{1,})):(\d+)%i', $buffer, $matches, PREG_SET_ORDER);
//var_dump( $matches[0] );
try{ $buffer .= 'msgstr "' . $matches[0][0] . '"' . "\n\n";} catch (Exception $e) {
$buffer .= 'msgstr "' . substr(md5($line),0,8). '"' . "\n";
}
} else if ( substr($next_line,0,12) == 'msgid_plural' ) {
$buffer .= $next_line;
$buffer .= 'msgstr[0] "' . substr(md5($line),0,8). '"' . "\n";
$buffer .= 'msgstr[1] "' . substr(md5($next_line),0,8). '"' . "\n\n";
}
fputs( $out, $buffer );
$buffer = "";
}
// if ( substr($line,0,6) == 'msgstr' )
// do nothing;
}
fclose( $in );
fclose( $out );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment