Skip to content

Commit

Permalink
Added po2json script (thanks to tvelter)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshas committed Aug 20, 2010
1 parent d752594 commit 48806b2
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tools/po2json.pl
@@ -0,0 +1,66 @@
#!/usr/bin/perl
# -*- coding: utf-8 -*-

# po transifex files to rosetta.js script by tvelter

use strict;
use warnings;
my $i = 0;my $j = 0;my $k = 0;
my @lang;my @label;my $dirname = "../skeleton/locale";my $filename ;
my %total;

opendir ( DIR, $dirname ) || die "Error in opening dir $dirname\n";
while( ($filename = readdir(DIR)))
{
next if $filename eq '.' or $filename eq '..';
my $docname = $dirname."\/".$filename ;
$lang[$j]= $filename;
$lang[$j]=~ s/.po$// ;
$lang[$j] = substr($lang[$j], -2);
open(my $file, "<", $docname) or die "Can't open file: $!";
my @temp = <$file>;
close $file or die "$file: $!";
$k=0;
for ($i = 1 ; $i != $#temp+1 ; $i++)
{
if ($temp[$i]=~ /^msgid/)
{
$label[$k] = $temp[$i];
$label[$k] =~ s/"$//;
$label[$k] =~ s/^msgid "//;
$temp[$i+1] =~ s/^msgstr/$lang[$j]:/;
$total {$lang[$j]} {$label[$k]} = $temp[$i+1] ;
$k +=1;
};
}
$j += 1;
}

closedir(DIR);
my $temp;
open (MYFILE, '>>../skeleton/overwrite/usr/share/plate/chrome/content/rosetta.txt');

print MYFILE "// Plate UI translation file, generated from po files\n\nvar i18n = {\n\n";
for ($j = 0 ; $j != $#label+1 ; $j++)
{
$temp= $label[$j];
$temp=~ s/$/ : {/;
print MYFILE "\t$temp";
for ($i = 0 ; $i != $#lang+1 ; $i++)
{
if ($label[$j] ne "")
{
if ($total {$lang[$i]} {$label[$j]} ne "$lang[$i]: \"\"\n")
{
$temp= $total {$lang[$i]} {$label[$j]};
$temp=~ s/$/,/;
print MYFILE "\t\t$temp";
}
}
}
print MYFILE "\t},\n\n";
}
print MYFILE "}";

print MYFILE "Bob\n";
close (MYFILE);

1 comment on commit 48806b2

@joshas
Copy link
Collaborator Author

@joshas joshas commented on 48806b2 Aug 20, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add this script to mkxpud build script when all translation files will be in correct format, because currently it gives many errors.

Please sign in to comment.