Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -w # # translate - Xchat Translation Script by shock # Site: http://www.exitwound.org # Email: shock@exitwound.org # # INSTALL: You MUST install the Lingua::Translate module # before using this script. See http://search.cpan.org to # locate it. # # The $DEFAULT variable should be set to your 2- or 3- # character language code (i.e., en for English, es for # Espanol, etc.). See below for how to locate other # character codes. # # Place translate.pl into your /home/<username>/.xchat/ # directory and restart xchat. # # OR # # Place translate.pl into your /home/<username>/.xchat/ # directory and type # "/load home/<username>/.xchat/translate.pl" into the # xchat window. # # You will see "translate 0.01 by shock has been # loaded" if the script loads properly. # # commands: Help screen = /translate # XX to Default Language = /pr XX::message # Default Language to XX = /tr XX::message # # Where XX is an acceptible language code as specified at # http://search.cpan.org/doc/JHI/perl-5.8.0-RC1/lib/I18N/LangTags/List +.pm # # If XX is not specified, the system defaults to Espanol. # # examples: # Assume you want to send a message in Spanish: # # /tr es::this is a test message # # Assume you have received a message in German: # # /pr de::dieses ist eine Testanzeige # # The /tr commands will post the message to the chatroom. # The /pr commands will only echo the translation to you. # No one in the chatroom will see it. # # # note 1: The Lingua::Translate module uses Babelfish # (http://babelfish.altavista.com) for it's translations. # So, although this module will allow you to communicate # in other languages, you're not going to to be the most # proficient of speakers. This module does NOT provide # (nor does it intend to) an ideal solution. It does, # however, allow you to somewhat break the language # barrier. # # note 2: Because the script has to contact Babelfish, # when you hit the enter key, you will notice a delay. # Sometimes it's a short delay, sometimes it's a long # delay. It all depends upon Internet traffic. # That's just the way it is, baby. # # ack: Thanks to BrainRawt (http://rawt.daemon.sh) for # writing Xchat scripts. I've used his scripts as a # go-by for this one. ################################## # DEFAULT LANGUAGE # ################################## # CHANGE THIS # # TO YOUR LANGUAGE # # # # Common choices: # # English = en # # Espanol = es # # German = de # # Italian = it # ################################## $DEFAULT = "en"; ################################## # VERSION NUMBER # ################################## $VER = "0.01"; IRC::register("translate", "$VER", "", ""); IRC::print("\0034translate $VER by shock has been loaded\003"); IRC::add_command_handler("translate", "help_handler"); IRC::add_command_handler("tr", "translation_handler"); IRC::add_command_handler("pr", "private_handler"); use Lingua::Translate; ################################## # HELP SCREEN # ################################## sub help_handler { IRC::command("/echo --------------------------"); IRC::command("/echo translate $VER help screen:"); IRC::command("/echo --------------------------"); IRC::command("/echo /tr XX::message - translates message from $DEF +AULT to XX in channel."); IRC::command("/echo /pr XX::message - from XX to $DEFAULT; Respons +e is echoed to user."); IRC::command("/echo --------------------------"); IRC::command("/echo XX is a two-character language tag."); IRC::command("/echo Espanol is the default if XX is not specified. +"); IRC::command("/echo See http://search.cpan.org/doc/JHI/perl-5.8.0- +RC1/lib/I18N/LangTags/List.pm for a list of acceptible language tags. +"); IRC::command("/echo --------------------------"); return 1; } ################################## # DEFAULT TRANSLATION # # From XX to User's Default # # Language # ################################## sub private_handler { my $language = shift(@_); if ($language =~ /(\w\w)::/) { ($src, $message) = split(/::/, $language); } else { $src = "es"; $message = $language; } my $xl8r = Lingua::Translate->new(src => "$src", dest => "$DEFAULT") or die "No translation server available for $src -> en"; my $english = $xl8r->translate($message); # dies or croaks on erro +r IRC::command("/echo $english"); return 1; } ################################## # USER-SPECIFIED TRANSLATION # # From User's Default # # Language to XX # ################################## sub translation_handler { my $language = shift(@_); if ($language =~ /(\w\w)::/) { ($dest, $message) = split(/::/, $language); } else { $dest = "es"; $message = $language; } my $xl8r = Lingua::Translate->new(src => "$DEFAULT", dest => "$dest") or die "No translation server available for en -> $dest"; my $translation = $xl8r->translate($message); # dies or croaks on +error IRC::command("$translation"); return 1; }

In reply to XChat Language Translator by shockme

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-19 19:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found