WWW::Wikipedia::LangTitles - get interwiki links from Wikipedia.
use utf8; use WWW::Wikipedia::LangTitles 'get_wiki_titles'; my $title = 'Three-phase electric power'; my $links = get_wiki_titles ($title); print "$title is '$links->{de}' in German.\n"; my $film = '東京物語'; my $flinks = get_wiki_titles ($film, lang => 'ja'); print "映画「$film」はイタリア語で'$flinks->{it}'と名付けた。\n";
produces output
Three-phase electric power is 'Dreiphasenwechselstrom' in German. 映画「東京物語」はイタリア語で'Viaggio a Tokyo'と名付けた。
(This example is included as synopsis.pl in the distribution.)
This documents version 0.02 of WWW::Wikipedia::LangTitles corresponding to git commit 3c7983f8baf6a0e3cf7931bcaf470549c81a8635 released on Sun Dec 25 12:59:42 2016 +0900.
This module retrieves the Wikipedia interwiki link titles from wikidata.org. It can be used, for example, to translate a term in English into other languages, or to get near equivalents.
my $ref = get_wiki_titles ('Helium');
Returns a hash reference with all the articles in each language, indexed by the language. For example $ref->{th} will be equal to ฮีเลียม, the Thai title of the equivalent Wikipedia article.
$ref->{th}
The language of the original page can be specified like this:
use utf8; my $from_th = get_wiki_titles ('ฮีเลียม', lang => 'th');
The URL is encoded using "uri_escape_utf8" in URI::Escape, so you must use character strings not byte strings (use "use utf8;" etc.)
An option "verbose" switches on verbose messages with any true value:
my $ref = get_wiki_titles ($name, verbose => 1);
my $url = make_wiki_url ('helium');
Make a URL for the Wikidata page. You will then need to retrieve the page and parse the JSON yourself. Use a second argument to specify the language of the page:
use utf8; my $url = make_wiki_url ('ฮีเลียม', 'th');
The default is en for English.
en
You may be able to convert the language codes to and from the language names using this module. (I have not tested it yet.)
Carp is used to report errors
LWP::UserAgent is used to retrieve the data from Wikidata.
JSON::Parse is used to parse the JSON data from Wikidata.
Ben Bullock, <bkb@cpan.org>
This package and associated files are copyright (C) 2016 Ben Bullock.
You can use, copy, modify and redistribute this package and associated files under the Perl Artistic Licence or the GNU General Public Licence.
To install WWW::Wikipedia::LangTitles, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::Wikipedia::LangTitles
CPAN shell
perl -MCPAN -e shell install WWW::Wikipedia::LangTitles
For more information on module installation, please visit the detailed CPAN module installation guide.