View | Details | Raw Unified | Return to bug 7327
Collapse All | Expand All

(-)a/misc/translator/TmplTokenizer.pm (+3 lines)
Lines 153-158 sub _split_js ($) { Link Here
153
        } elsif ($s0 =~ /^\/\*(?:(?!\*\/).)*\*\//s) {	# C-style comment
153
        } elsif ($s0 =~ /^\/\*(?:(?!\*\/).)*\*\//s) {	# C-style comment
154
            push @it, $&;
154
            push @it, $&;
155
            $s0 = $';
155
            $s0 = $';
156
        } elsif ($s0 =~ /^(?:(?:"(?:\\"|[^"])*"|'(?:\\'|[^'])*')|(?:[A-Za-z_][A-Za-z0-9_]*))(?:\s*\+\s*(?:(?:"(?:\\"|[^"])*"|'(?:\\'|[^'])*')|[A-Za-z_][A-Za-z0-9_]*))+/isg) { # Variable in string
157
            $s0 = $';
158
            push @it, "''+".$&."+''"; # This is so that the very first and last quotes are the same
156
        # Keyword or identifier, ECMA-262 p.13 (section 7.5)
159
        # Keyword or identifier, ECMA-262 p.13 (section 7.5)
157
        } elsif ($s0 =~ /^[A-Z_\$][A-Z\d_\$]*/is) {	# IdentifierName
160
        } elsif ($s0 =~ /^[A-Z_\$][A-Z\d_\$]*/is) {	# IdentifierName
158
            push @it, $&;
161
            push @it, $&;
(-)a/misc/translator/tmpl_process3.pl (-6 / +51 lines)
Lines 116-127 sub text_replace (**) { Link Here
116
    } elsif ($s->has_js_data) {
116
    } elsif ($s->has_js_data) {
117
        for my $t (@{$s->js_data}) {
117
        for my $t (@{$s->js_data}) {
118
        # FIXME for this whole block
118
        # FIXME for this whole block
119
        if ($t->[0]) {
119
            if ($t->[0]) {
120
            printf $output "%s%s%s", $t->[2], find_translation $t->[3],
120
                my $to_print;
121
                $t->[2];
121
                if ($t->[1] =~ /^(?:(?<startquote>")(?<startstring>(?:\\"|[^"])*)"|(?<startquote>')(?<startstring>(?:\\'|[^'])*)')(?<rest>(?:\s*\+\s*(?:(?:"(?:\\"|[^"])*"|'(?:\\'|[^'])*')|[A-Za-z_][A-Za-z0-9_]*))+)$/ig) {
122
        } else {
122
                    my @vars;
123
            print $output $t->[1];
123
                    my $quote = $+{startquote};
124
        }
124
                    my $to_parse = $+{startquote}.$+{rest};
125
                    my $to_translate = $+{startstring};
126
                    while (1) { # Loop through and substitute all vars with '%s'
127
                        if ($to_parse =~ /^$quote((?:\s*\+\s*[A-Za-z_][0-9A-Za-z_]*)\s*\+\s*)(?<nextquotes>['"])/isg) { # 1 var
128
                            push @vars, "'".$1."'";
129
                            $quote = $+{nextquotes};
130
                            $to_parse = $quote.$';
131
                            $to_translate .= '%s';
132
                        } elsif ($to_parse =~ /^$quote((?:\s*\+\s*[A-Za-z_][0-9A-Za-z_]*){2,})\s*\+\s*(?<nextquotes>['"])/isg) { # 2+ vars
133
                            $quote = $+{nextquotes};
134
                            $to_parse = $quote.$';
135
                            my @current_vars = split(/\s*\+\s*/,$1);
136
                            shift(@current_vars);
137
                            foreach my $var (@current_vars) {
138
                                $var = "'+".$var."+'";
139
                                $to_translate .= '%s';
140
                            }
141
                            push @vars, @current_vars;
142
                        } elsif ($to_parse =~ /^$quote\s*\+\s*(?<nextquotes>['"])/is) { # plus between two strings
143
                            $quote = $+{nextquotes};
144
                            $to_parse = $quote.$';
145
                        } elsif ($quote eq "'"  && $to_parse =~ /^'(?<text>(?:\\'|[^'])*?)'/is) { # 'string'
146
                            $to_parse = $quote.$';
147
                            $to_translate .= $+{text};
148
                            $to_translate =~ s/\\'/'/ig;
149
                        } elsif ($quote eq "\"" && $to_parse =~ /^"(?<text>(?:\\"|[^"])*?)"/is) { # "string"
150
                            $to_parse = $quote.$';
151
                            $to_translate .= $+{text};
152
                            $to_translate =~ s/\\"/"/ig;
153
                        } else {
154
                            last;
155
                        }
156
                    }
157
                    $to_print = find_translation($to_translate);
158
                    $to_print =~ s/'/\\'/ig;
159
                    foreach my $substitute (@vars) { # Substitute all '%s' with vars
160
                        $to_print =~ s/\%s/$substitute/i;
161
                    }
162
                    $t->[2] = "'";
163
                } else {
164
                    $to_print = find_translation($t->[3]);
165
                }
166
                printf $output "%s%s%s", $t->[2], $to_print, $t->[2];
167
            } else {
168
                print $output $t->[1];
169
            }
125
        }
170
        }
126
    } elsif (defined $t) {
171
    } elsif (defined $t) {
127
        # Quick fix to bug 4472
172
        # Quick fix to bug 4472
(-)a/misc/translator/xgettext.pl (-1 / +36 lines)
Lines 212-217 EOF Link Here
212
	} elsif ($text{$t}->[0]->has_js_data) {
212
	} elsif ($text{$t}->[0]->has_js_data) {
213
	    printf OUTPUT "#. For the first occurrence,\n" if @{$text{$t}} > 1;
213
	    printf OUTPUT "#. For the first occurrence,\n" if @{$text{$t}} > 1;
214
	    printf OUTPUT "#. SCRIPT\n";
214
	    printf OUTPUT "#. SCRIPT\n";
215
	    for my $jsdata (@{$text{$t}->[0]->js_data}) {
216
		if ($jsdata->[0]) {
217
		    if ($jsdata->[1] =~ /^(?:(?<startquote>")(?<startstring>(?:\\"|[^"])*)"|(?<startquote>')(?<startstring>(?:\\'|[^'])*)')(?<rest>(?:\s*\+\s*(?:(?:"(?:\\"|[^"])*"|'(?:\\'|[^'])*')|[A-Za-z_][A-Za-z0-9_]*))+)$/ig) {
218
			my $quote = $+{startquote};
219
			my $to_parse = $+{startquote}.$+{rest};
220
			my $to_store = $+{startstring};
221
			while (1) { # Loop through and substitute all vars with '%s'
222
			    if ($to_parse =~ /^$quote((?:\s*\+\s*[A-Za-z_][0-9A-Za-z_]*)\s*\+\s*)(?<nextquotes>['"])/isg) { # 1 var
223
				$quote = $+{nextquotes};
224
				$to_parse = $quote.$';
225
				$to_store .= '%s';
226
			    } elsif ($to_parse =~ /^$quote((?:\s*\+\s*[A-Za-z_][0-9A-Za-z_]*){2,})\s*\+\s*(?<nextquotes>['"])/isg) { # 2+ vars
227
				$quote = $+{nextquotes};
228
				$to_parse = $quote.$';
229
				my @current_vars = split(/\s*\+\s*/,$1);
230
				shift(@current_vars);
231
				$to_store .= '%s' foreach (@current_vars);
232
			    } elsif ($to_parse =~ /^$quote\s*\+\s*(?<nextquotes>['"])/is) { # plus between two strings
233
				$quote = $+{nextquotes};
234
				$to_parse = $quote.$';
235
			    } elsif ($quote eq "'"  && $to_parse =~ /^'(?<text>(?:\\'|[^'])*?)'/is) { # 'string'
236
				$to_parse = $quote.$';
237
				$to_store .= $+{text};
238
				$to_store =~ s/\\'/'/ig;
239
			    } elsif ($quote eq "\"" && $to_parse =~ /^"(?<text>(?:\\"|[^"])*?)"/is) { # "string"
240
				$to_parse = $quote.$';
241
				$to_store .= $+{text};
242
				$to_store =~ s/\\"/"/ig;
243
			    } else {
244
				last;
245
			    }
246
			}
247
			$t = $to_store;
248
		    }
249
		}
250
	    }
215
	}
251
	}
216
	my $cformat_p;
252
	my $cformat_p;
217
	for my $token (@{$text{$t}}) {
253
	for my $token (@{$text{$t}}) {
218
- 

Return to bug 7327