1Babelfish(3) User Contributed Perl Documentation Babelfish(3)
2
3
4
6 WWW::Babelfish - Perl extension for translation via Babelfish or Google
7
9 use WWW::Babelfish;
10 $obj = new WWW::Babelfish( service => 'Babelfish', agent => 'Mozilla/8.0', proxy => 'myproxy' );
11 die( "Babelfish server unavailable\n" ) unless defined($obj);
12
13 $french_text = $obj->translate( 'source' => 'English',
14 'destination' => 'French',
15 'text' => 'My hovercraft is full of eels',
16 'delimiter' => "\n\t",
17 'ofh' => \*STDOUT );
18 die("Could not translate: " . $obj->error) unless defined($french_text);
19
20 @languages = $obj->languages;
21
23 Perl interface to the WWW babelfish translation server.
24
26 new Creates a new WWW::Babelfish object.
27
28 Parameters:
29
30 service: Babelfish, Google or Yahoo; default is Babelfish
31 agent: user agent string
32 proxy: proxy in the form of host:port
33
34 services
35 Returns a plain array of the services available (currently
36 Babelfish, Google or Yahoo).
37
38 languages
39 Returns a plain array of the languages available for translation.
40
41 languagepairs
42 Returns a reference to a hash of hashes. The keys of the outer
43 hash reflect all available languages. The hashes the corresponding
44 values reference contain one (key) entry for each destination
45 language that the particular source language can be translated to.
46 The values of these inner hashes contain the Babelfish option name
47 for the language pair. You should not modify the returned
48 structure unless you really know what you're doing.
49
50 Here's an example of a possible return value:
51
52 {
53 'Chinese' => {
54 'English' => 'zh_en'
55 },
56 'English' => {
57 'Chinese' => 'en_zh',
58 'French' => 'en_fr',
59 'German' => 'en_de',
60 'Italian' => 'en_it',
61 'Japanese' => 'en_ja',
62 'Korean' => 'en_ko',
63 'Portuguese' => 'en_pt',
64 'Spanish' => 'en_es'
65 },
66 'French' => {
67 'English' => 'fr_en',
68 'German' => 'fr_de'
69 },
70 'German' => {
71 'English' => 'de_en',
72 'French' => 'de_fr'
73 },
74 'Italian' => {
75 'English' => 'it_en'
76 },
77 'Japanese' => {
78 'English' => 'ja_en'
79 },
80 'Korean' => {
81 'English' => 'ko_en'
82 },
83 'Portuguese' => {
84 'English' => 'pt_en'
85 },
86 'Russian' => {
87 'English' => 'ru_en'
88 },
89 'Spanish' => {
90 'English' => 'es_en'
91 }
92 };
93
94 translate
95 Translates some text using Babelfish.
96
97 Parameters:
98
99 source: Source language
100 destination: Destination language
101 text: If this is a reference, translate interprets it as an
102 open filehandle to read from. Otherwise, it is treated
103 as a string to translate.
104 delimiter: Paragraph delimiter for the text; the default is "\n\n".
105 Note that this is a string, not a regexp.
106 ofh: Output filehandle; if provided, the translation will be
107 written to this filehandle.
108
109 If no ofh parameter is given, translate will return the text;
110 otherwise it will return 1. On failure it returns undef.
111
112 error
113 Returns a (hopefully) meaningful error string.
114
116 Babelfish translates 1000 characters at a time. This module tries to
117 break the source text into reasonable logical chunks of less than 1000
118 characters, feeds them to Babelfish and then reassembles them.
119 Formatting may get lost in the process; also it's doubtful this will
120 work for non-Western languages since it tries to key on punctuation.
121 What would make this work is if perl had properly localized regexps for
122 sentence/clause boundaries.
123
124 Support for Google is preliminary and hasn't been extensively tested
125 (by me). Google's translations used to be suspiciously similar to
126 Babelfish's, but now some people tell me they're superior.
127
129 Dan Urist, durist@frii.com
130
132 perl(1).
133
134
135
136perl v5.28.0 2006-12-16 Babelfish(3)