LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-09-2011, 03:39 PM   #1
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Rep: Reputation: 255Reputation: 255Reputation: 255
Looking for a bash/sh script to translate a word with Internet (no package to install


Hello,

I would be glad if someone would have any ideas to translate a word with Internet (no package to install)?

Simple wget would be great

here some packages
http://ubuntuforums.org/archive/index.php/t-359574.html

Many thanks
Happy Tux
 
Old 08-09-2011, 03:55 PM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Hello,

From what language to what language are you looking to translate?

Cheers,

Josh
 
Old 08-09-2011, 04:02 PM   #3
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Never mind my last post, you just gave me a project

-Josh
 
Old 08-09-2011, 04:09 PM   #4
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Original Poster
Rep: Reputation: 255Reputation: 255Reputation: 255
Quote:
Originally Posted by corp769 View Post
Never mind my last post, you just gave me a project

-Josh
I like coding too... I never stop kind of doing sh (for cross platform)
( I usually try to avoid bash, and prefer sh for wider compatibility)

Last edited by Xeratul; 08-09-2011 at 04:10 PM.
 
Old 08-09-2011, 04:17 PM   #5
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Well before I decide to actually do it, I dug around a bit, and came across this - https://savannah.nongnu.org/projects/twandgtw/
What do you think of that?
 
Old 08-09-2011, 04:22 PM   #6
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
I found this on the Arch forums; it basically sends off $1 to Google Translate, GT translates the phrase/word/whatever (from the language you specify as $2; autodetect otherwise), then it snips out the actual translated word(s) from the wget'd page.

Code:
#!/bin/bash
wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=$2|${3:-en}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/';
The post I got it from

Hope this helps.
 
Old 08-09-2011, 04:31 PM   #7
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Quote:
Originally Posted by MrCode View Post
I found this on the Arch forums; it basically sends off $1 to Google Translate, GT translates the phrase/word/whatever (from the language you specify as $2; autodetect otherwise), then it snips out the actual translated word(s) from the wget'd page.

Code:
#!/bin/bash
wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=$2|${3:-en}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/';
The post I got it from

Hope this helps.
So I'm going to be "that guy" and one up you - http://www.commandlinefu.com/command...-in-mp3-format
Text to speech!
 
Old 08-09-2011, 04:45 PM   #8
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Original Poster
Rep: Reputation: 255Reputation: 255Reputation: 255
Quote:
Originally Posted by corp769 View Post
So I'm going to be "that guy" and one up you - http://www.commandlinefu.com/command...-in-mp3-format
Text to speech!
thanks. I remember i saw once that green page ...

We gotta make a $1, $2, ... for making our own script in an *.sh
Ipgeo.sh indeed rocks, and it says how to use it nice job
 
Old 08-09-2011, 04:51 PM   #9
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Well what exactly do you want in this script?
 
Old 08-09-2011, 05:48 PM   #10
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by MrCode View Post
I found this on the Arch forums; it basically sends off $1 to Google Translate, GT translates the phrase/word/whatever (from the language you specify as $2; autodetect otherwise), then it snips out the actual translated word(s) from the wget'd page.

Code:
#!/bin/bash
wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=$2|${3:-en}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/';
I think I read that Google is planning on removing the Google Translate API.
 
Old 08-09-2011, 07:26 PM   #11
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
I've improved the little "Google Translator script" thingy…it's in my LQ blog.
 
Old 08-09-2011, 07:30 PM   #12
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Quote:
Originally Posted by MrCode View Post
I've improved the little "Google Translator script" thingy…it's in my LQ blog.
Hmmm... I'm going to check out how many languages google supports. Maybe I can add some to your code?
 
Old 08-09-2011, 08:11 PM   #13
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
Quote:
Maybe I can add some to your code?
Err…how exactly do you mean? Do you mean somehow adding language support on the server end, or do you just mean giving some hints as to what languages are available (and maybe forcibly restricting the options to those languages)?

Anyway, as to your "one-up": you can just pipe the output of my blog script to espeak and have it speak out the translation.
 
Old 08-09-2011, 08:25 PM   #14
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Actually, I thought of something else dude....
Code:
#!/bin/bash
if [ "$1" = "--languages" ]; then
        echo ""
        echo "Supported languages:"
        echo ""
        echo "English - EN              Afrikaans - AF"
        echo "Albanian - SQ             Arabic - AR"
        echo "Armenian - HY             Azerbaijani - AZ"
        echo "Basque - EU               Belarusian - BE"
        echo "Bengali - BN              Bulgarian - BG"
        echo "Catalan - CA              Chinese - ZH"
        echo "Croatian - HR             Czech - CS"
        echo "Danish - DA               Dutch - NL"
        echo "Estonian - ET             Filipino - FIL (NOT TESTED)"
        echo "Finnish - FI              French - FR"
        echo "Galician - GL             Georgian - KA"
        echo "German - DE               Greek - EL"
        echo "Gujarati - GU             Haitian Creole - HT"
        echo "Hebrew - IW               Hindi - HI"
        echo "Hungarian - HU            Icelandic - IS"
        echo "Indonesian - IN           Irish - GA"
        echo "Italian - IT              Japanese - JA"
        echo "Kannada - KN              Korean - KO"
        echo "Latin - LA                Latvian - LV"
        echo "Lithuanian - LT           Macedonian - MK"
        echo "Malay - MS                Maltese - MT"
        echo "Norwegian - NO            Persian - FA"
        echo "Polish - PL               Portuguese - PT"
        echo "Romanian - RO             Russian - RU"
        echo "Serbian - SR              Slovak - SK"
        echo "Slovenian - SL            Spanish - ES"
        echo "Swahili - SW              Swedish - SV"
        echo "Tamil - TA                Telugu - TE"
        echo "Thai - TH                 Turkish - TR"
        echo "Ukrainian - UK            Urdu - UR"
        echo "Vietnamese - VI           Welsh - CY"
        echo "Yiddish - JI"
        echo ""
        exit
elif [ "$1" = "" -o "$2" = "" -o "$3" = "" ]; then
        echo "Usage: $0 \"<str>\" <lang1> <lang2>"
        echo "Translates string \"<str>\" from <lang1> to <lang2>"
        echo "(CLI frontend to Google Translate)"
        echo "Type $0 --languages for a list of supported languages."
        exit
else
        wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=$2|${3:-$3}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/';
fi
Now you have the full list of supported languages on google's end.....
 
Old 08-09-2011, 08:36 PM   #15
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Damn you and your ideas....
Code:
#!/bin/bash
text1=""
if [ "$1" = "--languages" ]; then
	echo ""
	echo "Supported languages:"
	echo ""
	echo "English - EN		Afrikaans - AF"
	echo "Albanian - SQ		Arabic - AR"
	echo "Armenian - HY		Azerbaijani - AZ"
	echo "Basque - EU		Belarusian - BE"
	echo "Bengali - BN		Bulgarian - BG"
	echo "Catalan - CA		Chinese - ZH"
	echo "Croatian - HR		Czech - CS"
	echo "Danish - DA		Dutch - NL"
	echo "Estonian - ET		Filipino - FIL (NOT TESTED)"
	echo "Finnish - FI		French - FR"
	echo "Galician - GL		Georgian - KA"
	echo "German - DE		Greek - EL"
	echo "Gujarati - GU		Haitian Creole - HT"
	echo "Hebrew - IW		Hindi - HI"
	echo "Hungarian - HU		Icelandic - IS"
	echo "Indonesian - IN		Irish - GA"
	echo "Italian - IT		Japanese - JA"
	echo "Kannada - KN		Korean - KO"
	echo "Latin - LA		Latvian - LV"
	echo "Lithuanian - LT		Macedonian - MK"
	echo "Malay - MS		Maltese - MT"
	echo "Norwegian - NO		Persian - FA"
	echo "Polish - PL		Portuguese - PT"
	echo "Romanian - RO		Russian - RU"
	echo "Serbian - SR		Slovak - SK"
	echo "Slovenian - SL		Spanish - ES"
	echo "Swahili - SW		Swedish - SV"
	echo "Tamil - TA		Telugu - TE"
	echo "Thai - TH 		Turkish - TR"
	echo "Ukrainian - UK		Urdu - UR"
	echo "Vietnamese - VI		Welsh - CY"
	echo "Yiddish - JI"
	echo ""
	exit
elif [ "$1" = "" -o "$2" = "" -o "$3" = "" ]; then
	echo "Usage: $0 \"<str>\" <lang1> <lang2>"
	echo "Translates string \"<str>\" from <lang1> to <lang2>"
	echo "(CLI frontend to Google Translate)"
	echo "Type $0 --languages for a list of supported languages."
	exit
else
	text1=`wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=$2|${3:-$3}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/';`
	echo ""
	echo "Original text: $1"
	echo "Converted text: $text1"
	echo ""
	read -p "Would you like the converted text spoken to you? [Yy/Nn]" answer
	if [ $answer = "Y" -o $answer = "y" ]; then
		espeak -v $3+f2 "$text1"
	fi
fi
I'm done until you think of something else to add
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Please translate this PHP script to BASH protorox Programming 8 03-28-2014 12:09 PM
bash shell script read file word by word part 2 justina Programming 7 01-25-2011 01:19 PM
[SOLVED] bash shell script read file word by word. justina Programming 15 01-22-2011 10:12 AM
BASH/No X: Using google translate to convert TXT files (translate) frenchn00b Programming 10 09-13-2009 10:55 PM
translate from word list in a file Critcho Linux - Newbie 1 03-20-2007 07:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration