in reply to Re: regex for translation
in thread regex for translation

Sure, one of the sentenses in templates reads
__("Thank you for choosing {T_SITE} for your reservation")
after tag replacement it will be
__("Thank you for choosing __("our system") for your reservation")
translation file contains this key >
__("Thank you for choosing new system for your reservation")
so I would need to take out tag that is going to be replaced from the sentense and add it as a parameter which can be parsed
__("Thank you for choosing [_0] for your reservation", {T_SITE})
After replacement it will be
__("Thank you for choosing [_0] for your reservation", __("our system"))
And both can be translated as >
Dziekujemy za wybranie [_0] do dokonania rezerwacji. and naszego systemu and add connect them as
Dziekujemy za wybranie naszego systemu do dokonania rezerwacji. problem is detecting where translation starts and where it ends and where parameters that I want to pass start and end. Regex that Ive posted is detecting that but unfortunately is very slow to use.

Replies are listed 'Best First'.
Re^3: regex for translation
by Anonymous Monk on Oct 02, 2013 at 15:13 UTC

    I'm sorry but I don't understand that any better than what you originally posted, too many targets

    Is this it?

    #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd pp /; my @stuff = ( { in => q{__("Thank you for choosing {T_SITE} for your reservation +")}, want => q{__("Thank you for choosing [_0] for your reservation",{T +_SITE})}, }, ); for my $test ( @stuff ){ my( $in, $want ) = @{$test}{qw/ in want /}; my $out = $in; $out =~ s{ (?: \Q__("\E (.+) # $1 \Q")\E ) }{ something( $1 ); }xegis; dd({ -in, $in, -out, $out, -want, $want }); } sub something { my( $what ) = @_; use vars '$fudge'; local $fudge; $what =~ s{ \{ ( [^\}]+ ) \} }{ $fudge = $1; q{[_0]} }sex; if( not defined $fudge){ } qq{__("$what",{$fudge})}; } __END__