intltool-merge.in

来自「memprof source code, linux」· IN 代码 · 共 658 行 · 第 1/2 页

IN
658
字号
#!@INTLTOOL_PERL@ -w##  The Intltool Message Merger##  Copyright (C) 2000, 2002 Free Software Foundation.#  Copyright (C) 2000, 2001 Eazel, Inc##  Intltool is free software; you can redistribute it and/or#  modify it under the terms of the GNU General Public License #  version 2 published by the Free Software Foundation.##  Intltool is distributed in the hope that it will be useful,#  but WITHOUT ANY WARRANTY; without even the implied warranty of#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU#  General Public License for more details.##  You should have received a copy of the GNU General Public License#  along with this program; if not, write to the Free Software#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.##  As a special exception to the GNU General Public License, if you#  distribute this file as part of a program that contains a#  configuration script generated by Autoconf, you may include it under#  the same distribution terms that you use for the rest of that program.##  Authors:  Maciej Stachowiak <mjs@noisehavoc.org>#            Kenneth Christiansen <kenneth@gnu.org>#            Darin Adler <darin@bentspoon.com>##  Proper XML UTF-8'ification written by Cyrille Chepelov <chepelov@calixo.net>### Release informationmy $PROGRAM = "intltool-merge";my $PACKAGE = "intltool";my $VERSION = "0.22";## Loaded modulesuse strict; use Getopt::Long;## Scalars used by the option stuffmy $HELP_ARG = 0;my $VERSION_ARG = 0;my $BA_STYLE_ARG = 0;my $XML_STYLE_ARG = 0;my $KEYS_STYLE_ARG = 0;my $DESKTOP_STYLE_ARG = 0;my $SCHEMAS_STYLE_ARG = 0;my $QUIET_ARG = 0;my $PASS_THROUGH_ARG = 0;my $UTF8_ARG = 0;my $cache_file;## Handle optionsGetOptions ( "help" => \$HELP_ARG, "version" => \$VERSION_ARG, "quiet|q" => \$QUIET_ARG, "oaf-style|o" => \$BA_STYLE_ARG, ## for compatibility "ba-style|b" => \$BA_STYLE_ARG, "xml-style|x" => \$XML_STYLE_ARG, "keys-style|k" => \$KEYS_STYLE_ARG, "desktop-style|d" => \$DESKTOP_STYLE_ARG, "schemas-style|s" => \$SCHEMAS_STYLE_ARG, "pass-through|p" => \$PASS_THROUGH_ARG, "utf8|u" => \$UTF8_ARG, "cache|c=s" => \$cache_file ) or &error;my $PO_DIR;my $FILE;my $OUTFILE;my %po_files_by_lang = ();my %translations = ();# Use this instead of \w for XML files to handle more possible characters.my $w = "[-A-Za-z0-9._:]";# XML quoted string contentsmy $q = "[^\\\"]*";## Check for options. if ($VERSION_ARG) {	&print_version;} elsif ($HELP_ARG) {	&print_help;} elsif ($BA_STYLE_ARG && @ARGV > 2) {	&preparation;	&print_message;	&ba_merge_translations;	&finalize;} elsif ($XML_STYLE_ARG && @ARGV > 2) {        &utf8_sanity_check;	&preparation;	&print_message;	&xml_merge_translations;	&finalize;} elsif ($KEYS_STYLE_ARG && @ARGV > 2) {        &utf8_sanity_check;        &preparation;        &print_message;        &keys_merge_translations;	&finalize;} elsif ($DESKTOP_STYLE_ARG && @ARGV > 2) {        &preparation;        &print_message;        &desktop_merge_translations;	&finalize;} elsif ($SCHEMAS_STYLE_ARG && @ARGV > 2) {        &preparation;        &print_message;        &schemas_merge_translations;	&finalize;} else {	&print_help;}exit;## Sub for printing release informationsub print_version{    print "${PROGRAM} (${PACKAGE}) ${VERSION}\n";    print "Written by Maciej Stachowiak, Darin Adler and Kenneth Christiansen.\n\n";    print "Copyright (C) 2000-2002 Free Software Foundation, Inc.\n";    print "Copyright (C) 2000-2001 Eazel, Inc.\n";    print "This is free software; see the source for copying conditions.  There is NO\n";    print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";    exit;}## Sub for printing usage informationsub print_help{    print "Usage: ${PROGRAM} [OPTIONS] PO_DIRECTORY FILENAME OUTPUT_FILE\n";    print "Generates an output file that includes translated versions of some attributes,\n";    print "from an untranslated source and a po directory that includes translations.\n\n";    print "  -b, --ba-style         includes translations in the bonobo-activation style\n";    print "  -d, --desktop-style    includes translations in the desktop style\n";    print "  -k, --keys-style       includes translations in the keys style\n";    print "  -s, --schemas-style    includes translations in the schemas style\n";    print "  -x, --xml-style        includes translations in the standard xml style\n";    print "  -u, --utf8             convert all strings to UTF-8 before merging\n";    print "  -p, --pass-through     use strings as found in .po files, without\n";    print "                         conversion (STRONGLY unrecommended with -x)\n";    print "  -q, --quiet            suppress most messages\n";    print "      --help             display this help and exit\n";    print "      --version          output version information and exit\n";    print "\nReport bugs to bugzilla.gnome.org, module intltool, or contact us through \n";    print "<xml-i18n-tools-list\@gnome.org>.\n";    exit;}## Sub for printing error messagessub print_error{    print "Try `${PROGRAM} --help' for more information.\n";    exit;}sub print_message {    print "Merging translations into $OUTFILE.\n" unless $QUIET_ARG;}sub preparation {    $PO_DIR = $ARGV[0];    $FILE = $ARGV[1];    $OUTFILE = $ARGV[2];    &gather_po_files;    &get_translation_database;}# General-purpose code for looking up translations in .po filessub po_file2lang{    my ($tmp) = @_;     $tmp =~ s/^.*\/(.*)\.po$/$1/;     return $tmp; }sub gather_po_files{    for my $po_file (glob "$PO_DIR/*.po") {	$po_files_by_lang{po_file2lang($po_file)} = $po_file;    }}sub get_po_encoding{    my ($in_po_file) = @_;    my $encoding = "";    open IN_PO_FILE, $in_po_file or die;    while (<IN_PO_FILE>) {        ## example: "Content-Type: text/plain; charset=ISO-8859-1\n"        if (/Content-Type\:.*charset=([-a-zA-Z0-9]+)\\n/) {            $encoding = $1;             last;        }    }    close IN_PO_FILE;    if (!$encoding) {        print "Warning: no encoding found in $in_po_file. Assuming ISO-8859-1\n";        $encoding = "ISO-8859-1";    }    return $encoding}sub utf8_sanity_check {    if (!$UTF8_ARG) {        if (!$PASS_THROUGH_ARG) {            $PASS_THROUGH_ARG="1";        }    }}sub get_translation_database{    if ($cache_file) {	&get_cached_translation_database;    } else {        &create_translation_database;    }}sub get_newest_po_age{    my $newest_age;    foreach my $file (values %po_files_by_lang) {	my $file_age = -M $file;	$newest_age = $file_age if !$newest_age || $file_age < $newest_age;    }    return $newest_age;}sub create_cache{    print "Generating and caching the translation database\n" unless $QUIET_ARG;    &create_translation_database;    open CACHE, ">$cache_file" || die;    print CACHE join "\x01", %translations;    close CACHE;}sub load_cache {    print "Found cached translation database\n" unless $QUIET_ARG;    my $contents;    open CACHE, "<$cache_file" || die;    {        local $/;        $contents = <CACHE>;    }    close CACHE;    %translations = split "\x01", $contents;}sub get_cached_translation_database{    my $cache_file_age = -M $cache_file;    if (defined $cache_file_age) {        if ($cache_file_age <= &get_newest_po_age) {            &load_cache;            return;        }        print "Found too-old cached translation database\n" unless $QUIET_ARG;    }    &create_cache;}sub create_translation_database{    for my $lang (keys %po_files_by_lang) {    	my $po_file = $po_files_by_lang{$lang};        if ($UTF8_ARG) {            my $encoding = get_po_encoding ($po_file);            if (lc $encoding eq "utf-8") {                open PO_FILE, "<$po_file";	            } else {                my $iconv = $ENV{"INTLTOOL_ICONV"} || "iconv";                open PO_FILE, "$iconv -f $encoding -t UTF-8 $po_file|";	            }        } else {            open PO_FILE, "<$po_file";	        }	my $nextfuzzy = 0;	my $inmsgid = 0;	my $inmsgstr = 0;	my $msgid = "";	my $msgstr = "";        while (<PO_FILE>) {	    $nextfuzzy = 1 if /^#, fuzzy/;            if (/^msgid "((\\.|[^\\])*)"/ ) {		$translations{$lang, $msgid} = $msgstr if $inmsgstr && $msgid && $msgstr;		$msgid = "";		$msgstr = "";		if ($nextfuzzy) {		    $inmsgid = 0;		} else {		    $msgid = unescape_po_string($1);		    $inmsgid = 1;		}		$inmsgstr = 0;		$nextfuzzy = 0;	    }	    if (/^msgstr "((\\.|[^\\])*)"/) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?