Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (3)
    As of 2020-10-22 18:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favourite web site is:












      Results (229 votes). Check out past polls.

      Notices?