CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Lingua-Translate

 



stormbanleader
Novice

May 3, 2011, 6:11 PM

Post #1 of 16 (2087 views)
Lingua-Translate Can't Post


Code
$translate=$_POST['translate']; 

use Lingua::Translate::config
(
backend => "Babelfish",
babelfish uri =>
'http://babelfish.yahoo.com/translate txt',
$ua => LWP::UserAgent->new(),
);

my $translate = Lingua::Translate->new(src => "en", dest=> "fr", "en", "de", "en", "it", "en", "pt", "en", "es", "en");

# prints "My hovercraft is full of eels"
print $translate->translate();


someone help me for starters i cannot get my code to connect to my installed script


miller
User

May 3, 2011, 6:45 PM

Post #2 of 16 (2084 views)
Re: [stormbanleader] Lingua-Translate [In reply to] Can't Post

Read the documentation for cpan Lingua::Translate closer.

- Miller


stormbanleader
Novice

May 3, 2011, 7:09 PM

Post #3 of 16 (2082 views)
Re: [miller] Lingua-Translate [In reply to] Can't Post


In Reply To
Read the documentation for cpan Lingua::Translate closer.

- Miller

well you are the expert i read through the tutorial several times and i just dont get it when i try and use the script i get an error that it cannot connect to the installed perl script i looked at some books in the google library and they dont mention anything about connecting your code to a perl script only connecting to a database


FishMonger
Veteran / Moderator

May 3, 2011, 7:58 PM

Post #4 of 16 (2078 views)
Re: [stormbanleader] Lingua-Translate [In reply to] Can't Post

The first step in getting help is to be able to provide a clear problem statement, which you have not done.

What is the exact wording of the error message?

At what point do you receive that error?

Exactly how are you executing your script?

When you say:

Quote
i cannot get my code to connect to my installed script

That tells me that the initial problem has nothing to do with the code you posted and doesn't make a lot of sense.


Quote

Code
$translate=$_POST['translate'];


That is not valid Perl code. It appears to be PHP code.

Do you have the following 2 lines in your script?

Code
use strict; 
use warnings;

If not, add them and run your script.


stormbanleader
Novice

May 3, 2011, 9:15 PM

Post #5 of 16 (2072 views)
Re: [FishMonger] Lingua-Translate [In reply to] Can't Post


In Reply To
The first step in getting help is to be able to provide a clear problem statement, which you have not done.

What is the exact wording of the error message?

At what point do you receive that error?

Exactly how are you executing your script?

When you say:

Quote
i cannot get my code to connect to my installed script

That tells me that the initial problem has nothing to do with the code you posted and doesn't make a lot of sense.


Quote

Code
$translate=$_POST['translate'];


That is not valid Perl code. It appears to be PHP code.

Do you have the following 2 lines in your script?

Code
use strict; 
use warnings;

If not, add them and run your script.


i am trying to create a mock up of my friends site he told me he would help me build one and i never got around to it

i need to take the inputted data from this form


Code
<form method="post" action="/Masks/In%20the%20process%20of%20transition.php"> 
<input type="hidden" name="submit" value="true" />
<textarea name="translate" cols="56" rows="5"></textarea>
<br /><br /><input type="submit" value="submit"></form><hr /></html>


the variable name is $translate=$post_['translate'];

i am posting it in the variable from the previous page

i even tried the original code


Code
#!/usr/bin/perl 
use strict; use warnings;
use WWW::Babelfish;
use Getopt::Long;
use IO::Prompt;

# map the language codes
my %language_code = (
fr => 'French',
es => 'Spanish',
de => 'German'
);

# parse command line arguments
my $translate_to_code;
my $result = GetOptions(
'translate-to=s' => $translate_to_code,
);
if (not $result) {
die "usage: ./translator.pl --translate-to fr | es | den";
}
if (not defined $translate_to_code) {
die "usage: ./translator.pl --translate-to fr | es | den";
}
if ($translate_to_code !~ /(fr)|(es)|(de)/) {
die "usage: ./translator.pl --translate-to fr | es | den";
}

# print instructions
print "nn";
print "Interactive Language Translator.n";
print "Enter text to translate at prompt.n";
print "Type 'EXIT' to quit.nn";

# create the Babelfish service
warn "Connecting to Babelfish service ...n";
my $service = WWW::Babelfish->new(
service => 'Babelfish',
);

# check for errors
if (not defined $service) {
die "Babelfish server unavailablen";
}

# loop while input is available
while ( prompt "text> " ) {
chomp;

# check if we need to exit
if ($_ =~ /^EXIT$/i) {
warn "Exiting ...n";
exit;
}

# translate
warn "Translating ...n";
my $translated_text = $service->translate(
source => 'English', # source language
destination => $language_code{$translate_to_code}, # destination language
text => $_ # text to translate
);
if (not defined $translated_text) {
warn "Error while translating.n";
}
else {
# output the translated text
print "[" . uc $translate_to_code . "] $translated_textn";
}
}


i still get the same error

Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' /Masks/In the process of transition.php on line 3

it successfully takes the information from the form but it does not know how to connect to the perl script i downloaded i have tried every combination i read on one tutorial the

Code
lwp

variable is where you define the connection however i was also tying to find a tutorial on that but i cannot find anything


FishMonger
Veteran / Moderator

May 4, 2011, 5:20 AM

Post #6 of 16 (2062 views)
Re: [stormbanleader] Lingua-Translate [In reply to] Can't Post

Your error message is coming from your PHP script, not the Perl script.

It would probably be best to post your question and PHP code in a PHP forum.


stormbanleader
Novice

May 4, 2011, 9:19 AM

Post #7 of 16 (2053 views)
Re: [FishMonger] Lingua-Translate [In reply to] Can't Post


In Reply To
Your error message is coming from your PHP script, not the Perl script.

It would probably be best to post your question and PHP code in a PHP forum.

to avoid coming back to this department and asking this question again from what i understand in the tutorials i use is to use perl code within a hyper text pre processor page how do i rig this thing up because i cannot find a tutorial at all that explains it


stormbanleader
Novice

May 4, 2011, 9:29 AM

Post #8 of 16 (2051 views)
Re: [FishMonger] Lingua-Translate [In reply to] Can't Post


In Reply To
Your error message is coming from your PHP script, not the Perl script.

It would probably be best to post your question and PHP code in a PHP forum.

also like i said before i deleted all of my hyper text pre processor code and just copied the code from the cspan repository and i still got the same error message without any hyper text pre processor code


FishMonger
Veteran / Moderator

May 4, 2011, 9:48 AM

Post #9 of 16 (2049 views)
Re: [stormbanleader] Lingua-Translate [In reply to] Can't Post

Well, you must have some php script running somewhere, because that error message is definitely coming from a php script, NOT from a perl script.


stormbanleader
Novice

May 4, 2011, 2:03 PM

Post #10 of 16 (2041 views)
Re: [FishMonger] Lingua-Translate [In reply to] Can't Post


In Reply To
Well, you must have some php script running somewhere, because that error message is definitely coming from a php script, NOT from a perl script.

its a hyper text pre processor file if you look at the form i posted and not a executable common gateway interface file


FishMonger
Veteran / Moderator

May 4, 2011, 3:29 PM

Post #11 of 16 (2036 views)
Re: [stormbanleader] Lingua-Translate [In reply to] Can't Post

You obviously don't understand what's going on, nor do you understand the meaning of CGI or PHP beyond the words in the acronyms.

The script you posted is a Perl script and has nothing to do with PHP. If you're attempting and expecting the php interpreter to parse/process/execute that script as is, then that would certainly explain the error.

PHP and Perl scripts are not interchangeable. It is possible to embed Perl code in a PHP script and have the php interpreter execute Perl code (by accessing the perl interpreter), IF the script is written for that purpose. The opposite is also true; there are Perl modules which allow you to embed PHP code in a Perl script. Your script is not written to do either. That script needs to be parsed/processed/executed by the perl interpreter, not the PHP interpreter.


stormbanleader
Novice

May 4, 2011, 5:42 PM

Post #12 of 16 (2030 views)
Re: [FishMonger] Lingua-Translate [In reply to] Can't Post


In Reply To
You obviously don't understand what's going on, nor do you understand the meaning of CGI or PHP beyond the words in the acronyms.

The script you posted is a Perl script and has nothing to do with PHP. If you're attempting and expecting the php interpreter to parse/process/execute that script as is, then that would certainly explain the error.

PHP and Perl scripts are not interchangeable. It is possible to embed Perl code in a PHP script and have the php interpreter execute Perl code (by accessing the perl interpreter), IF the script is written for that purpose. The opposite is also true; there are Perl modules which allow you to embed PHP code in a Perl script. Your script is not written to do either. That script needs to be parsed/processed/executed by the perl interpreter, not the PHP interpreter.

well atleast someone here gets it the reference materials i have say that if you direct you hyper text preprocessor to the directory in which your perl script is installed and piggy back your code on top of that then you can interchange data fairly easily between the form and the perl script but that is what the tutorial said however anytime i put that

Code
# user/bin/perl

it interprets it as comments instead of a direct connection to the directory where perl is installed but i have not been able to trouble shoot past the connection stage beyond that i could probably do some more experimenting and figure out how to code the translations


FishMonger
Veteran / Moderator

May 4, 2011, 6:20 PM

Post #13 of 16 (2027 views)
Re: [stormbanleader] Lingua-Translate [In reply to] Can't Post

I've only skimmed over a portion of these articles, but they seem to be credible sources.

http://www.linuxjournal.com/article/9282

http://devzone.zend.com/article/1712


FishMonger
Veteran / Moderator

May 4, 2011, 6:33 PM

Post #14 of 16 (2026 views)
Re: [stormbanleader] Lingua-Translate [In reply to] Can't Post

Since you appear to know very little (almost nothing) about each language, my recommendation is to forget about trying to incorporate both of them, and instead you really should focus on learning one of them and use it for your project. Once you're comfortable and reasonably knowledgeable in that language, learn the other and only when you're comfortable with both, should you work on incorporating both.


stormbanleader
Novice

May 4, 2011, 9:04 PM

Post #15 of 16 (2021 views)
Re: [FishMonger] Lingua-Translate [In reply to] Can't Post


In Reply To
I've only skimmed over a portion of these articles, but they seem to be credible sources.

http://www.linuxjournal.com/article/9282

http://devzone.zend.com/article/1712


http://www.chicagonow.com/blogs/photos/assets_c/2009/09/snl-dratch-thumb-autox580-18357.jpghttp://ia.media-imdb.com/images/M/MV5BMTM4ODM2NDA1Nl5BMl5BanBnXkFtZTcwMjk0OTgwMw@@._V1._SX640_SY944_.jpg


stormbanleader
Novice

May 7, 2011, 4:35 PM

Post #16 of 16 (1985 views)
Re: [FishMonger] Lingua-Translate [In reply to] Can't Post


In Reply To
Since you appear to know very little (almost nothing) about each language, my recommendation is to forget about trying to incorporate both of them, and instead you really should focus on learning one of them and use it for your project. Once you're comfortable and reasonably knowledgeable in that language, learn the other and only when you're comfortable with both, should you work on incorporating both.

this is the website i want to reproducehttp://tashian.com/multibabel/however it has not worked in over a month and i have been using it for years all i get when i try and access this page is this weird kind of dust that you find on the exhaust fans in middle school gym class i looked at the links you sent me and i finally got around to downloaded the hyper text pre processor and perl extension that allows the two to communicate however it is way over the top for me and maybe someone can give me a little training on what exactly i am supposed to do because the books i bought on perl dont mention anything about haveing to install anything beyond the tools i am trying to use but i havent even gotten that far anytime i try and skip to a new line the stupid perl command prompt thing just closes i dont know how to do any of it i thought you just pump some code into an offline web page it would bean off to yahoo but its not working

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives