My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env perl
use strict;
use warnings;
use Locale::PO;
use JSON::Syck;
$JSON::Syck::ImplicitUnicode = 1;
use IO::All;
use HTML::Entities;
use Encode;
use utf8;
use encoding 'utf8';

sub po2json {
my ($in, $out) = @_;
my $po = new Locale::PO();
my $po_href = Locale::PO->load_file_ashash( $in );
my %h;
for my $msgid (keys %$po_href) {
my ($k, $v) = map {
my $s = $po->dequote($_);
$s =~ s/(.)/encode_entities($1)/ge;
$s
} ($msgid, $po_href->{$msgid}->{msgstr});
next unless $k && $v;
$h{ $k } = $v;
}
io($out)->assert->print( JSON::Syck::Dump(\%h) )
}

if(! $ARGV[1] ) {
die <<USAGE
Usage: $0 po_file json_file
USAGE
}

po2json(@ARGV);


Change log

r116 by gugodliu on May 12, 2007   Diff
 r14392@GOP:  gugod | 2007-05-12 23:15:51
+0800
 po2json.pl - convert po files to json
format.

Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 748 bytes, 38 lines
Powered by Google Project Hosting