Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: regex for translation

by Anonymous Monk
on Oct 02, 2013 at 08:53 UTC ( [id://1056587]=note: print w/replies, xml ) Need Help??


in reply to regex for translation

Could there be any simpler solution to this problem?

Um, maybe, if the sample input and wanted output was presented

Replies are listed 'Best First'.
Re^2: regex for translation
by klayman (Initiate) on Oct 02, 2013 at 13:10 UTC
    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.

      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__

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1056587]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-26 06:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found