| 1 | #!/usr/bin/perl -w |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | |
|---|
| 5 | use lib 'lib'; |
|---|
| 6 | use lib 'extlib'; |
|---|
| 7 | use File::Spec; |
|---|
| 8 | use MT; |
|---|
| 9 | use MT::Util qw(encode_js); |
|---|
| 10 | |
|---|
| 11 | my $js = `cat mt-static/mt.js`; |
|---|
| 12 | $js .= `cat mt-static/js/edit.js`; |
|---|
| 13 | $js .= `cat mt-static/js/archetype_editor.js`; |
|---|
| 14 | $js .= `cat mt-static/js/dialog.js`; |
|---|
| 15 | $js .= `cat mt-static/js/assetdetail.js`; |
|---|
| 16 | $js .= `cat tmpl/cms/edit_template.tmpl`; |
|---|
| 17 | $js .= `cat tmpl/cms/edit_entry.tmpl`; |
|---|
| 18 | $js .= `cat tmpl/cms/widget/blog_stats.tmpl`; |
|---|
| 19 | $js .= `cat tmpl/cms/list_tag.tmpl`; |
|---|
| 20 | $js .= `cat tmpl/cms/include/calendar.tmpl`; |
|---|
| 21 | |
|---|
| 22 | my $addon_path = File::Spec->catdir( 'addons' ); |
|---|
| 23 | local *DH; |
|---|
| 24 | my @files; |
|---|
| 25 | if ( opendir DH, $addon_path ) { |
|---|
| 26 | my @p = readdir DH; |
|---|
| 27 | foreach my $p (@p) { |
|---|
| 28 | next if $p eq '.' || $p eq '..'; |
|---|
| 29 | my $full_path = File::Spec->catdir( $addon_path, $p ); |
|---|
| 30 | if ( -d $full_path ) { |
|---|
| 31 | if ( $p =~ m/^(.+)\.(\w+)$/ ) { |
|---|
| 32 | my $label = $1; |
|---|
| 33 | my $id = lc $1; |
|---|
| 34 | my $type = $2; |
|---|
| 35 | next if $type ne 'pack'; |
|---|
| 36 | if ( open my $fh, '<', File::Spec->catfile($full_path, 'make_js_templates') ) { |
|---|
| 37 | while (<$fh>) { |
|---|
| 38 | chomp $_; |
|---|
| 39 | push @files, $_; |
|---|
| 40 | } |
|---|
| 41 | close $fh; |
|---|
| 42 | } |
|---|
| 43 | } |
|---|
| 44 | } |
|---|
| 45 | } |
|---|
| 46 | closedir DH; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | $js .= `cat $_` foreach @files; |
|---|
| 50 | |
|---|
| 51 | foreach my $lang (qw(ja de nl fr es)) { |
|---|
| 52 | eval 'require MT::L10N::' . $lang |
|---|
| 53 | or die "failed to find package MT::L10N::$lang"; |
|---|
| 54 | |
|---|
| 55 | my $lex = eval '\%{ %MT::L10N::' . $lang . '::Lexicon }'; |
|---|
| 56 | $js =~ s/\\'/\t\t/g; |
|---|
| 57 | my %lexicon; |
|---|
| 58 | while ($js =~ m/trans\((["'])([^\1|\\\1]+?)\1/g) { |
|---|
| 59 | my $str = $2; |
|---|
| 60 | $str =~ s/\t\t/'/g; |
|---|
| 61 | my $local = $lex->{$str} || $str; |
|---|
| 62 | $str = encode_js($str); |
|---|
| 63 | $local = encode_js($local); |
|---|
| 64 | next if $str eq $local; |
|---|
| 65 | $lexicon{$str} = $local; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | open(FOUT, ">./mt-static/mt_$lang.js") |
|---|
| 69 | or die "failed to open mt-static/mt_$lang.js for writing"; |
|---|
| 70 | |
|---|
| 71 | print FOUT "/* Movable Type language lexicon for $lang localization. */\n\n"; |
|---|
| 72 | |
|---|
| 73 | for my $text ( keys %lexicon ) { |
|---|
| 74 | print FOUT "Lexicon['$text'] = '$lexicon{$text}';\n"; |
|---|
| 75 | } |
|---|
| 76 | close(FOUT); |
|---|
| 77 | } |
|---|