root/branches/release-28/build/mt-dists/make-js @ 1381

Revision 1381, 2.6 kB (checked in by fumiakiy, 22 months ago)

Made make-js aware of addons. BugId:62681 BugId:68263

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl -w
2
3use strict;
4
5use lib 'lib';
6use lib 'extlib';
7use File::Spec;
8use MT;
9use MT::Util qw(encode_js);
10
11my $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
22my $addon_path = File::Spec->catdir( 'addons' );
23local *DH;
24my @files;
25my @addons;
26if ( opendir DH, $addon_path ) {
27    my @p = readdir DH;
28    foreach my $p (@p) {
29        next if $p eq '.' || $p eq '..';
30        my $full_path = File::Spec->catdir( $addon_path, $p );
31        if ( -d $full_path ) {
32            if ( $p =~ m/^(.+)\.(\w+)$/ ) {
33                my $label = $1;
34                my $id    = lc $1;
35                my $type  = $2;
36                next if $type ne 'pack';
37                if ( open my $fh, '<', File::Spec->catfile($full_path, 'make_js_templates') ) {
38                    while (<$fh>) {
39                        chomp $_;
40                        push @files, $_;
41                    }
42                    close $fh;
43                    push @addons, $label;
44                }
45            }
46        }
47    }
48    closedir DH;
49}
50
51$js .= `cat $_` foreach @files;
52
53foreach my $lang (qw(ja de nl fr es)) {
54    eval 'require MT::L10N::' . $lang
55        or die "failed to find package MT::L10N::$lang";
56
57    my $lex = eval '\%{ %MT::L10N::' . $lang . '::Lexicon }';
58
59    foreach my $addon (@addons) {
60        eval {
61            unshift @INC, "addons/$addon.pack/lib";
62            require "addons/$addon.pack/lib/MT/$addon/L10N/$lang.pm";
63        };
64        my $conv;
65        unless ($@) {
66            $conv = eval '\%{MT::' . $addon . '::L10N::' . $lang . '::Lexicon}';
67        }
68        if ( %$conv ) {
69            $lex = {
70                %$lex,
71                %$conv,
72            };
73        }
74    }
75
76    $js =~ s/\\'/\t\t/g;
77    my %lexicon;
78    while ($js =~ m/trans\((["'])([^\1|\\\1]+?)\1/g) {
79        my $str = $2;
80        $str =~ s/\t\t/'/g;
81        my $local = $lex->{$str} || $str;
82        $str = encode_js($str);
83        $local = encode_js($local);
84        next if $str eq $local;
85        $lexicon{$str} = $local;
86    }
87
88    open(FOUT, ">./mt-static/mt_$lang.js")
89        or die "failed to open mt-static/mt_$lang.js for writing";
90
91    print FOUT "/* Movable Type language lexicon for $lang localization. */\n\n";
92
93    for my $text ( keys %lexicon ) {
94        print FOUT "Lexicon['$text'] = '$lexicon{$text}';\n";
95    }
96    close(FOUT);
97}
Note: See TracBrowser for help on using the browser.