2 # -*- Mode: perl; indent-tabs-mode: nil; c-basic-offset: 4 -*-
5 # The Intltool Message Extractor
7 # Copyright (C) 2000-2001, 2003 Free Software Foundation.
9 # Intltool is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation; either version 2 of the
12 # License, or (at your option) any later version.
14 # Intltool is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 # As a special exception to the GNU General Public License, if you
24 # distribute this file as part of a program that contains a
25 # configuration script generated by Autoconf, you may include it under
26 # the same distribution terms that you use for the rest of that program.
28 # Authors: Kenneth Christiansen <kenneth@gnu.org>
29 # Darin Adler <darin@bentspoon.com>
32 ## Release information
33 my $PROGRAM = "intltool-extract";
34 my $PACKAGE = "@PACKAGE@";
35 my $VERSION = "@VERSION@";
42 ## Scalars used by the option stuff
46 my $VERSION_ARG = "0";
50 my $NOMSGCTXT_ARG = "0";
55 my $gettext_type = "";
58 my @messages_sorted = ();
66 ## Use this instead of \w for XML files to handle more possible characters.
67 my $w = "[-A-Za-z0-9._:]";
74 "type=s" => \$TYPE_ARG,
75 "local|l" => \$LOCAL_ARG,
76 "help|h" => \$HELP_ARG,
77 "version|v" => \$VERSION_ARG,
78 "update" => \$UPDATE_ARG,
79 "quiet|q" => \$QUIET_ARG,
80 "srcdir=s" => \$SRCDIR_ARG,
81 "nomsgctxt" => \$NOMSGCTXT_ARG,
88 ## This section will check for the different options.
90 sub split_on_argument {
98 } elsif ($LOCAL_ARG) {
102 } elsif ($UPDATE_ARG) {
106 } elsif (@ARGV > 0) {
119 $OUTFILE = "$FILE.h";
121 my $dirname = dirname ($OUTFILE);
122 if (! -d "$dirname" && $dirname ne "") {
123 system ("mkdir -p $dirname");
129 $OUTFILE = fileparse($FILE, ());
131 system("mkdir tmp/");
133 $OUTFILE = "./tmp/$OUTFILE.h"
137 if ($TYPE_ARG =~ /^gettext\/(.*)/) {
142 ## Sub for printing release information
145 ${PROGRAM} (${PACKAGE}) $VERSION
146 Copyright (C) 2000, 2003 Free Software Foundation, Inc.
147 Written by Kenneth Christiansen, 2000.
149 This is free software; see the source for copying conditions. There is NO
150 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
155 ## Sub for printing usage information
158 Usage: ${PROGRAM} [OPTION]... [FILENAME]
159 Generates a header file from an XML source file.
161 It grabs all strings between <_translatable_node> and its end tag in
162 XML files. Read manpage (man ${PROGRAM}) for more info.
164 --type=TYPE Specify the file type of FILENAME. Currently supports:
165 "gettext/glade", "gettext/ini", "gettext/keys"
166 "gettext/rfc822deb", "gettext/schemas",
167 "gettext/gsettings", "gettext/xml", "gettext/quoted",
168 "gettext/quotedxml", "gettext/tlk", "gettext/qtdesigner"
169 -l, --local Writes output into current working directory
170 (conflicts with --update)
171 --update Writes output into the same directory the source file
172 reside (conflicts with --local)
173 --srcdir Root of the source tree
174 -v, --version Output version information and exit
175 -h, --help Display this help and exit
176 -q, --quiet Quiet mode
178 Report bugs to http://bugs.launchpad.net/intltool
183 ## Sub for printing error messages
185 print STDERR "Try `${PROGRAM} --help' for more information.\n";
190 print "Generating C format header file for translation.\n" unless $QUIET_ARG;
198 open OUT, ">$OUTFILE";
199 binmode (OUT) if $^O eq 'MSWin32';
203 print "Wrote $OUTFILE\n" unless $QUIET_ARG;
211 local $/; #slurp mode
212 open (IN, "<$SRCDIR_ARG/$FILE") || die "can't open $SRCDIR_ARG/$FILE: $!";
218 &type_ini if $gettext_type eq "ini";
219 &type_keys if $gettext_type eq "keys";
220 &type_xml if $gettext_type eq "xml";
221 &type_glade if $gettext_type eq "glade";
222 &type_gsettings if $gettext_type eq "gsettings";
223 &type_schemas if $gettext_type eq "schemas";
224 &type_rfc822deb if $gettext_type eq "rfc822deb";
225 &type_quoted if $gettext_type eq "quoted";
226 &type_quotedxml if $gettext_type eq "quotedxml";
227 &type_tlk if $gettext_type eq "tlk";
228 &type_qtdesigner if $gettext_type eq "qtdesigner";
231 sub entity_decode_minimal
257 return '\"' if $_ eq '"';
258 return '\n' if $_ eq "\n";
259 return '\\\\' if $_ eq '\\';
267 return join "", map &escape_char, split //, $string;
273 push @messages_sorted, $string if !defined $messages{$string};
274 $messages{$string} = [];
278 ### For generic translatable desktop files ###
279 while ($input =~ /^(#(.+)\n)?^_[A-Za-z0-9\-]+\s*=\s*(.*)$/mg) {
288 ### For generic translatable mime/keys files ###
289 while ($input =~ /^\s*_\w+=(.*)$/mg) {
295 ### For generic translatable XML files ###
296 my $tree = readXml($input);
302 my $vartype = ref $var;
304 if ($vartype =~ /ARRAY/) {
307 foreach my $el (@arr) {
312 } elsif ($vartype =~ /HASH/) {
315 foreach my $key (keys %hash) {
317 print_var($hash{$key});
326 # Same syntax as getAttributeString in intltool-merge.in.in, similar logic (look for ## differences comment)
327 sub getAttributeString
330 my $do_translate = shift || 1;
331 my $language = shift || "";
332 my $translate = shift;
334 foreach my $e (reverse(sort(keys %{ $sub }))) {
336 my $string = $sub->{$e};
339 $string =~ s/^[\s]+//;
340 $string =~ s/[\s]+$//;
342 if ($string =~ /^'.*'$/)
346 $string =~ s/^['"]//g;
347 $string =~ s/['"]$//g;
349 ## differences from intltool-merge.in.in
351 $comments{entity_decode($string)} = $XMLCOMMENT if $XMLCOMMENT;
352 add_message(entity_decode($string));
355 ## differences end here from intltool-merge.in.in
356 $result .= " $key=$quote$string$quote";
361 # Verbatim copy from intltool-merge.in.in
365 my $spacepreserve = shift || 0;
366 my @list = @{ $ref };
369 my $count = scalar(@list);
370 my $attrs = $list[0];
373 $spacepreserve = 1 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?preserve["']?$/));
374 $spacepreserve = 0 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?default["']?$/));
376 while ($index < $count) {
377 my $type = $list[$index];
378 my $content = $list[$index+1];
382 # lets strip the whitespace here, and *ONLY* here
383 $content =~ s/\s+/ /gs if (!$spacepreserve);
386 } elsif ( "$type" ne "1" ) {
387 # We've got another element
389 $result .= getAttributeString(@{$content}[0], 0); # no nested translatable elements
391 my $subresult = getXMLstring($content, $spacepreserve);
393 $result .= ">".$subresult . "</$type>";
406 # Verbatim copy from intltool-merge.in.in, except for MULTIPLE_OUTPUT handling removed
407 # Translate list of nodes if necessary
408 sub translate_subnodes
412 my $language = shift || "";
413 my $singlelang = shift || 0;
414 my $spacepreserve = shift || 0;
416 my @nodes = @{ $content };
418 my $count = scalar(@nodes);
420 while ($index < $count) {
421 my $type = $nodes[$index];
422 my $rest = $nodes[$index+1];
423 traverse($fh, $type, $rest, $language, $spacepreserve);
428 # Based on traverse() in intltool-merge.in.in
431 my $fh = shift; # unused, to allow us to sync code between -merge and -extract
432 my $nodename = shift;
434 my $language = shift || "";
435 my $spacepreserve = shift || 0;
437 if ($nodename && "$nodename" eq "1") {
438 $XMLCOMMENT = $content;
439 } elsif ($nodename) {
441 my @all = @{ $content };
442 my $attrs = shift @all;
444 my $outattr = getAttributeString($attrs, 1, $language, \$translate);
446 if ($nodename =~ /^_/) {
452 $spacepreserve = 0 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?default["']?$/));
453 $spacepreserve = 1 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?preserve["']?$/));
456 $lookup = getXMLstring($content, $spacepreserve);
457 if (!$spacepreserve) {
458 $lookup =~ s/^\s+//s;
459 $lookup =~ s/\s+$//s;
461 if (exists $attrs->{"msgctxt"}) {
462 my $context = entity_decode ($attrs->{"msgctxt"});
463 $context =~ s/^["'](.*)["']/$1/;
464 $lookup = "$context\004$lookup";
467 if ($lookup && $translate != 2) {
468 $comments{$lookup} = $XMLCOMMENT if $XMLCOMMENT;
469 add_message($lookup);
470 } elsif ($translate == 2) {
471 translate_subnodes($fh, \@all, $language, 1, $spacepreserve);
475 my $count = scalar(@all);
478 while ($index < $count) {
479 my $type = $all[$index];
480 my $rest = $all[$index+1];
481 traverse($fh, $type, $rest, $language, $spacepreserve);
491 # Verbatim copy from intltool-merge.in.in, $fh for compatibility
496 my $language = shift || "";
498 my $name = shift @{ $ref };
499 my $cont = shift @{ $ref };
501 while (!$name || "$name" eq "1") {
502 $name = shift @{ $ref };
503 $cont = shift @{ $ref };
506 my $spacepreserve = 0;
507 my $attrs = @{$cont}[0];
508 $spacepreserve = 1 if ((exists $attrs->{"xml:space"}) && ($attrs->{"xml:space"} =~ /^["']?preserve["']?$/));
510 traverse($fh, $name, $cont, $language, $spacepreserve);
513 # Verbatim copy from intltool-merge.in.in
514 sub intltool_tree_comment
517 my $data = $expat->original_string();
518 my $clist = $expat->{Curlist};
523 push @$clist, 1 => $data;
526 # Verbatim copy from intltool-merge.in.in
527 sub intltool_tree_cdatastart
530 my $clist = $expat->{Curlist};
533 push @$clist, 0 => $expat->original_string();
536 # Verbatim copy from intltool-merge.in.in
537 sub intltool_tree_cdataend
540 my $clist = $expat->{Curlist};
543 $clist->[$pos] .= $expat->original_string();
546 # Verbatim copy from intltool-merge.in.in
547 sub intltool_tree_char
551 my $clist = $expat->{Curlist};
554 # Use original_string so that we retain escaped entities
557 if ($pos > 0 and $clist->[$pos - 1] eq '0') {
558 $clist->[$pos] .= $expat->original_string();
560 push @$clist, 0 => $expat->original_string();
564 # Verbatim copy from intltool-merge.in.in
565 sub intltool_tree_start
571 # Use original_string so that we retain escaped entities
572 # in attribute values. We must convert the string to an
573 # @origlist array to conform to the structure of the Tree
576 my @original_array = split /\x/, $expat->original_string();
577 my $source = $expat->original_string();
579 # Remove leading tag.
581 $source =~ s|^\s*<\s*(\S+)||s;
583 # Grab attribute key/value pairs and push onto @origlist array.
587 if ($source =~ /^\s*([\w:-]+)\s*[=]\s*["]/)
589 $source =~ s|^\s*([\w:-]+)\s*[=]\s*["]([^"]*)["]||s;
591 push @origlist, '"' . $2 . '"';
593 elsif ($source =~ /^\s*([\w:-]+)\s*[=]\s*[']/)
595 $source =~ s|^\s*([\w:-]+)\s*[=]\s*[']([^']*)[']||s;
597 push @origlist, "'" . $2 . "'";
605 my $ol = [ { @origlist } ];
607 push @{ $expat->{Lists} }, $expat->{Curlist};
608 push @{ $expat->{Curlist} }, $tag => $ol;
609 $expat->{Curlist} = $ol;
612 # Copied from intltool-merge.in.in and added comment handler.
615 my $xmldoc = shift || return;
616 my $ret = eval 'require XML::Parser';
618 die "You must have XML::Parser installed to run $0\n\n";
620 my $xp = new XML::Parser(Style => 'Tree');
621 $xp->setHandlers(Char => \&intltool_tree_char);
622 $xp->setHandlers(Start => \&intltool_tree_start);
623 $xp->setHandlers(CdataStart => \&intltool_tree_cdatastart);
624 $xp->setHandlers(CdataEnd => \&intltool_tree_cdataend);
626 ## differences from intltool-merge.in.in
627 $xp->setHandlers(Comment => \&intltool_tree_comment);
628 ## differences end here from intltool-merge.in.in
630 my $tree = $xp->parse($xmldoc);
632 # <foo><!-- comment --><head id="a">Hello <em>there</em></head><bar>Howdy<ref/></bar>do</foo>
634 # [foo, [{}, 1, "comment", head, [{id => "a"}, 0, "Hello ", em, [{}, 0, "there"]], bar,
635 # [{}, 0, "Howdy", ref, [{}]], 0, "do" ] ]
641 ### For schemas XML files ###
643 # FIXME: We should handle escaped < (less than)
645 <locale\ name="C">\s*
646 (<default>\s*(?:<!--([^>]*?)-->\s*)?(.*?)\s*<\/default>\s*)?
647 (<short>\s*(?:<!--([^>]*?)-->\s*)?(.*?)\s*<\/short>\s*)?
648 (<long>\s*(?:<!--([^>]*?)-->\s*)?(.*?)\s*<\/long>\s*)?
651 my @totranslate = ($3,$6,$9);
652 my @eachcomment = ($2,$5,$8);
653 foreach (@totranslate) {
654 my $currentcomment = shift @eachcomment;
657 add_message(entity_decode_minimal($_));
658 $comments{entity_decode_minimal($_)} = $currentcomment if (defined($currentcomment));
663 # Parse the tree as returned by readXml() for gschema.xml files.
664 sub traverse_gsettings {
672 my $nodename = shift;
674 my $comment = shift || 0;
675 my @list = @{ $content };
676 my $attrs_ref = shift @list;
677 my %attrs = %{ $attrs_ref };
678 if (($nodename eq 'default' and $attrs{'l10n'}) or
679 ($nodename eq 'summary') or ($nodename eq 'description')) {
680 # preserve whitespace. deal with it ourselves, below.
681 my $message = getXMLstring($content, 1);
683 if ($nodename eq 'default') {
684 # for <default> we strip leading and trailing whitespace but
685 # preserve (possibly quoted) whitespace within
686 $message =~ s/^\s+//;
687 $message =~ s/\s+$//;
689 # for <summary> and <description>, we normalise all
690 # whitespace while preserving paragraph boundaries
691 $message = join "\n\n", map &cleanup, split/\n\s*\n+/, $message;
694 my $context = $attrs{'context'};
695 $context =~ s/^["'](.*)["']/$1/ if $context;
696 $message = $context . "\004" . $message if $context;
697 add_message($message);
698 $comments{$message} = $comment if $comment;
702 while (scalar(@list) > 1) {
703 my $type = shift @list;
704 my $content = shift @list;
705 if (!$type || "$type" eq "1") {
711 traverse_gsettings($type, $content, $comment);
719 my $tree = readXml($input);
720 my @tree_nodes = @{ $tree };
721 my $node = shift @tree_nodes;
722 while (!$node || "$node" eq "1") {
724 $node = shift @tree_nodes;
726 my $content = shift @tree_nodes;
727 traverse_gsettings($node, $content);
731 ### For rfc822-style Debian configuration files ###
735 while ($input =~ /\G(.*?)(^|\n)(_+)([^:]+):[ \t]*(.*?)(?=\n\S|$)/sg)
737 my ($pre, $newline, $underscore, $tag, $text) = ($1, $2, $3, $4, $5);
738 while ($pre =~ m/\n/g)
742 $lineno += length($newline);
743 my @str_list = rfc822deb_split(length($underscore), $text);
744 for my $str (@str_list)
748 $loc{$str} = $lineno;
749 $count{$str} = $strcount;
750 my $usercomment = '';
751 while($pre =~ s/(^|\n)#([^\n]*)$//s)
753 $usercomment = "\n" . $2 . $usercomment;
755 $comments{$str} = $tag . $usercomment;
757 $lineno += ($text =~ s/\n//g);
761 sub rfc822deb_split {
762 # Debian defines a special way to deal with rfc822-style files:
763 # when a value contain newlines, it consists of
764 # 1. a short form (first line)
765 # 2. a long description, all lines begin with a space,
766 # and paragraphs are separated by a single dot on a line
767 # This routine returns an array of all paragraphs, and reformat
769 # When first argument is 2, the string is a comma separated list of
773 $text =~ s/^[ \t]//mg;
774 return (split(/, */, $text, 0)) if $type ne 1;
775 return ($text) if $text !~ /\n/;
777 $text =~ s/([^\n]*)\n//;
780 for my $line (split (/\n/, $text))
783 if ($line =~ /^\.\s*$/)
790 elsif ($line =~ /^\s/)
792 # Line which must not be reformatted
793 $str .= "\n" if length ($str) && $str !~ /\n$/;
799 # Continuation line, remove newline
800 $str .= " " if length ($str) && $str !~ /\n$/;
805 push(@list, $str) if length ($str);
810 while ($input =~ /\"(([^\"]|\\\")*[^\\\"])\"/g) {
813 $message =~ s/\\\"/\"/g;
814 $before =~ s/[^\n]//g;
815 add_message($message);
816 $loc{$message} = length ($before) + 2;
821 while ($input =~ /\"(([^\"]|\\\")*[^\\\"])\"/g) {
824 $message =~ s/\\\"/\"/g;
825 $message = entity_decode($message);
826 $before =~ s/[^\n]//g;
827 add_message($message);
828 $loc{$message} = length ($before) + 2;
832 # Parse the tree as returned by readXml() for Qt Designer .ui files.
833 sub traverse_qtdesigner {
834 my $nodename = shift;
836 my @list = @{ $content };
837 my $attrs_ref = shift @list;
838 my %attrs = %{ $attrs_ref };
839 if ($nodename eq 'string' and !exists $attrs{"notr"}) {
840 # Preserve whitespace. Deal with it ourselves, below.
841 my $message = getXMLstring($content, 1);
843 # We strip leading and trailing whitespace but
844 # preserve whitespace within (e.g. newlines)
845 $message =~ s/^\s+//;
846 $message =~ s/\s+$//;
848 my $context = $attrs{'comment'};
849 # Remove enclosing quotes from msgctxt
850 $context =~ s/^["'](.*)["']/$1/ if $context;
851 $message = $context . "\004" . $message if $context;
852 add_message($message);
853 my $comment = $attrs{'extracomment'};
854 # Remove enclosing quotes from developer comments
855 $comment =~ s/^["'](.*)["']/$1/ if $comment;
856 $comments{$message} = $comment if $comment;
859 while (scalar(@list) > 1) {
860 my $type = shift @list;
861 my $content = shift @list;
862 if (!$type || "$type" eq "1") {
865 traverse_qtdesigner($type, $content);
871 sub type_qtdesigner {
872 ### For translatable Qt Designer XML files ###
876 # - http://qt-project.org/doc/qt-5.0/qtlinguist/linguist-ts-file-format.html
877 # - http://qt-project.org/doc/qt-5.0/qtdesigner/designer-ui-file-format.html
879 # <string> tag attributes:
881 # notr="true" means the string is not translatable
882 # extracomment maps to a developer comment in gettext
883 # comment corresponds to "disambiguation" in the Qt Linguist API, and maps
884 # to msgctxt in gettext
888 # <string comment="Button" extracomment="TRANSLATORS: refers to the
889 # action of accepting something">Ok</string>
891 my $tree = readXml($input);
892 my @tree_nodes = @{ $tree };
893 my $node = shift @tree_nodes;
894 while (!$node || "$node" eq "1") {
896 $node = shift @tree_nodes;
898 my $content = shift @tree_nodes;
899 traverse_qtdesigner($node, $content);
904 ### For translatable Glade XML files ###
906 my $tags = "label|title|text|format|copyright|comments|preview_text|tooltip|message";
908 while ($input =~ /<($tags)>([^<]+)<\/($tags)>/sg) {
909 # Glade sometimes uses tags that normally mark translatable things for
910 # little bits of non-translatable content. We work around this by not
911 # translating strings that only includes something like label4 or window1.
912 add_message(entity_decode($2)) unless $2 =~ /^(window|label|dialog)[0-9]+$/;
915 while ($input =~ /<items>(..[^<]*)<\/items>/sg) {
916 for my $item (split (/\n/, $1)) {
917 add_message(entity_decode($item));
921 ## handle new glade files
922 while ($input =~ /<(\w+)\s+[^>]*translatable\s*=\s*["']yes["'](?:\s+[^>]*context\s*=\s*["']([^"']*)["'])?(?:\s+[^>]*comments\s*=\s*["']([^"']*)["'])?[^>]*>([^<]+)<\/\1>/sg) {
923 if (!($4 =~ /^(window|label)[0-9]+$/)) {
924 my $message = entity_decode($4);
926 $message = entity_decode($2) . "\004" . $message;
928 add_message($message);
930 $comments{$message} = entity_decode($3) ;
934 while ($input =~ /<atkaction\s+action_name="([^>]*)"\s+description="([^>]+)"\/>/sg) {
935 add_message(entity_decode_minimal($2));
940 my ($ftype, $fvers, $langid, $strcount, $stroff);
943 my @inputa = split (//, $input, 21);
947 $ftype = substr ($input, 0, 3);
948 $fvers = substr ($input, 4, 7);
949 $langid = unpack ("L", $inputa[8] . $inputa[9] .
950 $inputa[10] . $inputa[11]);
951 $strcount = unpack ("L", $inputa[12] . $inputa[13] .
952 $inputa[14] . $inputa[15]);
953 $stroff = unpack ("L", $inputa[16] . $inputa[17] .
954 $inputa[18] . $inputa[19]);
957 $strdata = bytes::substr ($input, $stroff);
961 $foo = $inputa[$sinpos];
963 @inputa = split (//, $foo, $sinpos + 1);
966 while ($count < $strcount) {
967 my ($flags, $soundref, $volvar, $pitch, $offset, $strsize, $sndlen) = 0;
969 if ($count > 0 && $count % 2000 == 0) {
970 $foo = $inputa[$sinpos];
971 my $numleft = ($strcount - $count);
972 if ($numleft > 2000) {
975 $sinpos = 40 * $numleft;
977 @inputa = split (//, $foo, $sinpos + 1);
978 my $numbytes = @inputa;
983 $flags = unpack ("L", $inputa[$pos] . $inputa[$pos + 1] .
984 $inputa[$pos + 2] . $inputa[$pos + 3]);
986 if ($flags & 0x0002) {
987 $soundref = join ('', @inputa[$pos..$pos + 15]);
988 $soundref =~ s/\0//g;
991 # According to the Bioware Aurora Talk Table Format documentation
992 # the VolumeVariance and PitchVariance DWORDs are not used
993 # We increment the pos counter, but do not read the data, here
994 # $volvar = unpack ("L", $inputa[$pos] . $inputa[$pos + 1] .
995 # $inputa[$pos + 2] . $inputa[$pos + 3]);
997 # $pitch = unpack ("L", $inputa[$pos] . $inputa[$pos + 1] .
998 # $inputa[$pos + 2] . $inputa[$pos + 3]);
1000 $offset = unpack ("L", $inputa[$pos] . $inputa[$pos + 1] .
1001 $inputa[$pos + 2] . $inputa[$pos + 3])
1002 if ($flags & 0x0001);
1004 $strsize = unpack ("L", $inputa[$pos] . $inputa[$pos + 1] .
1005 $inputa[$pos + 2] . $inputa[$pos + 3])
1006 if ($flags & 0x0001);
1008 $sndlen = unpack ("d", $inputa[$pos] . $inputa[$pos + 1] .
1009 $inputa[$pos + 2] . $inputa[$pos + 3])
1010 if ($flags & 0x0004);
1013 if (defined $strsize && $strsize > 0) {
1014 my $message = substr ($strdata, $offset, $strsize);
1015 if (defined $message) {
1017 Encode::from_to ($message, "iso-8859-1", "UTF-8");
1018 add_message($message);
1019 if ($message =~ /^Bad Strref$/ ) {
1020 $comments{$message} = "DO NOT Translate this Entry.";
1021 $comments{$message} .= "\nTLK:position=$count";
1023 $comments{$message} = "TLK:position=$count";
1024 $comments{$message} .= "; TLK:sndresref=$soundref"
1025 if (defined $soundref && $soundref ne "");
1026 $comments{$message} .= "; TLK:sndlen=$sndlen"
1027 if (defined $sndlen && $sndlen != 0);
1030 print STDERR "Missing message? ID: $count\n";
1041 @msgids = sort { $count{$a} <=> $count{$b} } keys %count;
1045 @msgids = @messages_sorted;
1047 for my $message (@msgids)
1049 my $offsetlines = 1;
1050 my $context = undef;
1051 $offsetlines++ if $message =~ /%/;
1052 if (defined ($comments{$message}))
1054 while ($comments{$message} =~ m/\n/g)
1059 print OUT "# ".($loc{$message} - $offsetlines). " \"$FILE\"\n"
1060 if defined $loc{$message};
1061 print OUT "/* ".$comments{$message}." */\n"
1062 if defined $comments{$message};
1063 print OUT "/* xgettext:no-c-format */\n" if $message =~ /%/;
1065 if ($message =~ /(.*)\004(.*)/s) {
1069 my @lines = split (/\n/, $message, -1);
1070 for (my $n = 0; $n < @lines; $n++)
1074 if (defined $context)
1078 print OUT "char *s = N_(\"", $context, "|";
1082 print OUT "char *s = C_(\"", $context, "\", \"";
1087 print OUT "char *s = N_(\"";
1095 print OUT escape($lines[$n]);
1097 if ($n < @lines - 1)
1099 print OUT "\\n\"\n";