ForumNewsMembersSearchRegisterMember LoginFree Forum!


Neuer Thread ...


AuthorTopics » Book an abo for this threadClose Thread Move Thread Fix the thread Print view Delete this thread

jkohen ...



...

Status:Offline
Date registered: 26.02.2007
Post:2
Send Message
...   Created on 08.03.2007 - 22:20Jump to top Quote this post Report this post Edit Delete


This Perl script merges an AGS translation with a blank dialog translation. Dialog indexes are honored, so that the translated text gets a translation index as well. If a speechref file is supplied, it is translated as well, to help dubbers working on a translated text.

OK, what is this useful for?
If you want to add dubbing to your game after it's been translated, you need to create a new translation template. This template will be empty, and copying all the text from your old translation files by hand is a burdesome task. This script automates the task by merging the old translation with the new translation template, so that you can create translated talkies more easily.

Additionally, it can translate speechref files, so that the dubbers will be able to see the line of text in the translated language as well as in the original as they record their vocies.

Requirements: Perl 5, an AGS translation template and at least one translation.

Code:
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:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
 

#!/usr/bin/perl -w
#
# Merges a translation with a blank dialog translation. Dialog indexes
# are honored, so that the translated text gets a translation index as
# well. If a speechref file is supplied, it is translated as well, to
# help dubbers working on a translated text.
#
# Invocation: perl dubtrans translation.txt dubbed_translation_template.txt [speechref.txt]
# Output: dubbed_translation.txt and optionally speechref_translation.txt.
# Output files are overwritten, if they exist. Previous versions are backed
# up with a "~" postfix.
#
# Author: Javier Kohen <jkohen@users.sourceforge.net>
# Test material supplied by Le Woltaire - http://spectrum.sitesled.com/
# Hereby donated to the public domain.
# Please notify me of any improvements you make to this script.
#
# Last update: 2007-03-08 21:00Z

use strict;

use FileHandle;
use File::Copy;

my $dubtrans_fn = "dubbed_translation.txt";
my $sptrans_fn = "speechref_translation.txt";


# Indicates the start of a block containing messages we are interested
# in dubbing.
my $MAKE = '^\/\/ \*\*\*\* (?:(?:.* MESSAGES|STRINGS FROM THE GLOBAL SCRIPT) ARE BELOW|LINES ADDED IN UPDATE AT .*) \*\*\*\*$';

# Indicates a section change.
my $BREAK = '^\/\/ \*\*\*\*';

sub show_help();
sub build_dictionary($$);
sub translate_template($$$);

## Check input.

# A standard AGS translation file.
my $trans_fn = shift @ARGV or show_help and die "Must supply a translation source.\n";

# A translation template. It should contain dub indexes.
my $tpl_fn = shift @ARGV or show_help and die "Must supply a dubbed translation template.\n";

# The speechref file, if given.
my $spref_fn = shift @ARGV;

## Build translation table.

# Keep translation table in memory, for now.
my %DICT;

build_dictionary($trans_fn, \%DICT);

## Translate translation template.

translate_template(\%DICT, $tpl_fn, $dubtrans_fn);

## Translate speechref, if given.

translate_template(\%DICT, $spref_fn, $sptrans_fn) if defined $spref_fn;


## End of main.

sub show_help() {
    print "Invocation: $0 translation.txt dubbed_translation_template.txt [speechref.txt]\n";
    print "Output: dubbed_translation.txt and optionally speechref_translation.txt\n";
}

sub build_dictionary($$) {
    my $trans_fn = shift;
    my $dict = shift;

    my $trans = new FileHandle $trans_fn, "r" or die "Cannot open translation";

    my $capturing = 0;
    my $pos = 0; # Oscillates back and forth to indicate source text or translation.
    my $key;
    while (<$trans>) {
    if (/$BREAK/) {
        $capturing = 0;
    }

    if ($capturing) {
        # Remove line separator.
        chomp;
        # Remove dub index, if present.
        s/^&[\d]+ //;

        if (0 == (1 & $pos)) {
        $key = $_;
        } else {
        if (length) {
            $$dict{$key} = $_;
        }
        }

        $pos ^= 1;
    }

    if (/$MAKE/) {
        $capturing = 1;
        $pos = 0;
    }
    }
    undef $trans;
}

sub translate_template($$$) {
    my $dict = shift;
    my $src_fn = shift;
    my $dst_fn = shift;

    my $in = new FileHandle $src_fn, "r" or die "Cannot open translation template";
    move($dst_fn, "$dst_fn~"); # Backup output, if it exists.
    my $out = new FileHandle $dst_fn, "w" or die "Cannot open dubbed translation for writing";

    my $capturing = 0;
    my $pos = 0; # Oscillates back and forth to indicate source text or translation.
    my $key;
    my $char_name;
    my $index;

    ## For each line beginning with &, look up translation, prepend the
    ## index, and output that as the next line.
    while (<$in>) {
    if (/$BREAK/) {
        $capturing = 0;
    }

    my $line = $_;

    if ($capturing) {
        # Remove line separator.
        chomp;
        # Extract character name and dub index, if present.
        s/^(.{4}:)?(&[\d]+) //;
        if (0 == (1 & $pos)) {
        $key = $_;
        $char_name = $1;
        $index = $2;
        } else {
        my $val = $$dict{$key};
        if (defined $val and defined $index) {
            $line = "$index $val\n";
            $line = $char_name . $line if defined $char_name;
        }
        }

        $pos ^= 1;
    }

    if (/$MAKE/) {
        $capturing = 1;
        $pos = 0;
    }

    $out->print($line);
    }

    undef $in;
    undef $out;
}




Le_Woltaire ...
Administrator
...............

...

Status:Offline
Date registered: 21.02.2007
Post:89
Send Message
...   Created on 09.03.2007 - 18:52Jump to top Quote this post Report this post Edit Delete


It also has to be mentioned, that the template you create is made after you used the autonumber option in AGS.

So with this script you transfer your translated material into the empty autonumbered source and it will get numbered as well during this process.

The script is not useful if you can't or don't want to autonumber your game. In this case jkohen's other script is more useful.





Signature


Neuer Thread ...

Birthdays:
There are no birthday children today!
----------------------------------




Masthead

This forum is a free service of razyboard.com
Do you want a free forum in less than two minutes? Then click here!



Verwandte Suchbegriffe:
open ags translation files
blank