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: '<a href="http://translate.google.com/#en|ca|">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 :) Thanks! Bernat Romagosa. _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
2009/12/8 AxiNat <[hidden email]>:
> 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: <http://stackoverflow.com/questions/1136604/how-do-i-use-the-json-google-translate-api>. url := WAUrl absolute: 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&ie=UTF8'. url addParameter: 'langpair' value: 'de|en'. url addParameter: 'q' value: 'Wenn wir uns selbst fehlen, fehlt uns doch alles.'. 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. Cheers, Lukas -- Lukas Renggli http://www.lukas-renggli.ch _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
In reply to this post by Bernat Romagosa
Hi,
Lukas solution is far more better. But Soup should work too. Did you pass the string to translate because http://translate.google.com/#en|fr| is the default url and translation is done by "ajax" on the fly. Otherwise, the string to translate is encodeed at the end of the url.
For instance, try with http://translate.google.com/#en|fr|a%20string%20to%20translate ?
hth, Cédrick 2009/12/8 AxiNat <[hidden email]> Hi all! you can also search for span whose title are each line you want to translate.
-- Cédrick _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
Hi,
Thank you very much, Lukas' solution is working :) Cédrick, I forgot to add the string to be translated in the e-mail, but I was using it in the original code hehe Bernat.
2009/12/8 Cédrick Béler <[hidden email]> Hi, -- O HAI I'M IN UR FOOTER SIGNATURING UR MAILZ _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
Free forum by Nabble | Edit this page |