vebaev
Member
From: Bulgaria, Plovdiv
Registered: 2013-09-09
Posts: 77
Hi,
Do you know a method for translating a list of words, for example if I have 300 vocab words, i tried google translator but it is quite buggy?
Last edited by vebaev (2013 December 25, 1:19 pm)
jmignot
Member
From: France
Registered: 2006-03-03
Posts: 205
lauri_ranta wrote:
If you use OS X or Linux, you can add one word per line in ~/Desktop/words.txt and run a command like this in a terminal:
curl ringtail.its.monash.edu.au/pub/nihongo/edict.gz|gzip -d|iconv -f euc-jp -t utf-8 >~/Desktop/edict;for word in $(<~/Desktop/words.txt);do grep "^$word " ~/Desktop/edict;done
I tried but it returned an error in OSX:
curl ringtail.its.monash.edu.au/pub/nihongo/edict.gz|gzip -d|iconv -f euc-jp -t utf-8 >~/Desktop/edict;for word in $(<~/Desktop/words.txt);do grep "^$word " ~/Desktop/edict;done
Illegal variable name.
Is there a typo in this command (copy-pasted from your post)?
Last edited by jmignot (2013 December 29, 2:32 am)
jmignot wrote:
I tried but it returned an error in OSX
The command worked for me when I copied and pasted it from the post. If your shell is csh, try using bash instead. csh can be the default shell if you have a really old version of OS X or if you have upgraded from an old version of OS X.
Here's a Ruby script that should also work out of the box in (relatively new versions of) OS X:
edict = {}
IO.read("JMdict_e").scan(/<entry>.*?<\/entry>/m).each { |entry|
keb = entry[/(?<=<keb>).*(?=<\/keb>)/] || next
reb = entry[/(?<=<reb>).*(?=<\/reb>)/]
next if edict[keb]
gloss = entry[/(?<=<gloss>).*(?=<\/gloss>)/]
gloss = gloss.sub(/^(\([^)]+\) )*/, "").sub(/ \([^)]+\)$/, "")
edict[keb] = [reb, gloss]
}
IO.read("words.txt").split.each { |word|
reb, gloss = edict[word] || next
puts word + "\t" + reb + "\t" + gloss
}
You can run the script by for example saving it as jmdict.rb in the home folder, putting http://ringtail.its.monash.edu.au/pub/nihongo/JMdict_e and words.txt in the home folder, and then running "ruby jmdict.rb" in Terminal.