http://www.perlmonks.org?node_id=1021054

welle has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying of getting the tranlation in a given language of the "title" of a Wikipedia's entry. I'am using wwww::Wikipedia. I need first to know in which languages an entry is available. To do this I do:

#!/usr/bin/perl -w use WWW::Wikipedia; use Encode; my $wiki = WWW::Wikipedia->new(); my $entry = $wiki->search( 'Rotation' ); my @languages_available = $entry->languages(); foreach (@languages_available) { print "$_\n"; }

Unfortunately this doesn't produce any results. What I am doing wrong?

Replies are listed 'Best First'.
Re: WWW::Wikipeida getting translation
by toolic (Bishop) on Feb 28, 2013 at 13:21 UTC
    It produces "en" for me:
    use warnings; use strict; use WWW::Wikipedia; use Encode; my $wiki = WWW::Wikipedia->new(); my $entry = $wiki->search( 'Rotation' ); my @languages_available = $entry->languages(); foreach (@languages_available) { print "$_\n"; } __END__ en

    Maybe you can use Data::Dumper to see what $entry has for you:

    use Data::Dumper; print Dumper($entry);

      Yes, good idea with Data::Dumper. It really seams there is only EN. But that is strange, as the Wikipedia entry has more connected languages (if I open it in a browser). Maybe it is a bag of the www::wikipedia module

Re: WWW::Wikipeida getting translation
by Not_a_Number (Prior) on Feb 28, 2013 at 18:51 UTC

    Hmmm...

    Changing the search term yields different results. For instance, for 'clam', I get:

    da de en eo fi gl ja

    which is nevertheless still far fewer than the 20+ languages shown in my browser.

    A bit of poking about in the Data::Dumper output as suggested by toolic shows these lines towards the end

    [[da:Musling]] [[de:Muscheln]] [[eo:Pekteno]] [[gl:Ameixa, molusco]] [[ja:\x{30cf}\x{30de}\x{30b0}\x{30ea}]] [[fi:Simpukat]]

    which obviously correspond, apart from en, but don't appear in the browser-rendered version.

    But what I'm wondering is where you found the languages() method documented? It's not in the POD for WWW::Wikipedia.
      But what I'm wondering is where you found the languages() method documented? It's not in the pod for WWW::Wikipedia.
      I wondered the same thing. I looked in the source for WWW::Wikipedia, and I found:
      use WWW::Wikipedia::Entry;

      The POD for WWW::Wikipedia::Entry has languages(). The POD for WWW::Wikipedia should mention WWW::Wikipedia::Entry.

Re: WWW::Wikipeida getting translation
by LTjake (Prior) on Mar 01, 2013 at 14:12 UTC

    Hi. I'm the current maintainer of WWW::Wikipedia. I can tell you that the results from wikipedia have been slightly odd of late on the language front.

    I recently released version 2.01 because our language test was failing -- trying to grab the english page for "Russia" then grabbing the russian version. The languages returned were no longer as expected.

    As far as "Rotation" goes. Here is what we parse: http://en.wikipedia.org/w/index.php?title=Rotation&action=raw

    as you can see, there are no language links in the stream. Perhaps we should send an inquiry to wikipedia/wikimedia on the matter?

      Hi LTjake

      Thank you for your reply. Yes, there is something strange in the language behaviour. I encounterd problems in the last weeks. I don't really know how your module parses data, but it would be great to have your fantastic module working properly. The language funtionalities are one of the best things around. We (academics) are using it with lot of success. Would be possible to directly parse the html output from Wikipedia? Let me know if you have some news!

        Here's the thread I started on the wikipedia tech list:

        http://thread.gmane.org/gmane.science.linguistics.wikipedia.technical/68186

        As you can see, I received a reply quite quickly, though the answer suggests that some work will have to be done in order to make things work again. Sadly.

        --
        "Go up to the next female stranger you see and tell her that her "body is a wonderland."
        My hypothesis is that she’ll be too busy laughing at you to even bother slapping you.
        " (src)