renggli at gmail.com
Tue Dec 8 09:18:08 UTC 2009
2009/12/8 AxiNat <tibabenfortlapalanca at gmail.com>:
> Hi all!
> I'm developing a Seaside app that needs to retrieve a translation from
> google translator, so I thought I'd use Soup.
> So i go like:
> aSoup := Soup fromUrl: 'http://translate.google.com/#en|ca|'
> but i find that the fetched string is a bit different from the actual source
> code i can see in Mozilla...
> results := aSoup findAllTags: [:aTag |
> aTag name = 'span' and:
> [(aTag attributeAt: 'id') asString beginsWith: 'result_box']].
> results contains the correct tag, but the tag contains an empty string,
> instead of the translation (it holds the translated string when I check the
> HTML source in firefox)
> Any ideas? I find it really awkward, I've worked with soup before and never
> had such problem... so I'm kinda clueless.
> Sorry if the question is a bit off-topic (not exactly a Seaside issue...), I
> just guessed that a lot of seasiders sure must have dealt with Soup quite a
> few times :)
Luckily I could avoid it in the past 8 years :-)
I don't have a solution for your particular problem, but using the
Google JSON API and the JSON parser that comes with Seaside 3.0 this
works really well. I followed the instructions given here:
url := WAUrl absolute:
url addParameter: 'langpair' value: 'de|en'.
url addParameter: 'q' value: 'Wenn wir uns selbst fehlen, fehlt uns
response := JSJsonParser parseStream: (HTTPSocket httpGet: url printString).
((response at: 'responseData') at: 'translatedText')
The above workspace code doesn't deal with encodings (that would have
to be fixed), but it basically works.
More information about the seaside