View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Enrique Nell > WWW-Translate-Apertium > WWW::Translate::Apertium



Annotate this POD


Open  1
View/Report Bugs
Module Version: 0.16   Source  


WWW::Translate::Apertium - Open source machine translation


Version 0.16 September 6, 2010


    use WWW::Translate::Apertium;
    my $engine = WWW::Translate::Apertium->new();
    my $translated_string = $engine->translate($string);
    # default language pair is Catalan -> Spanish
    # change to Spanish -> Galician:
    # check current language pair:
    my $current_langpair = $engine->from_into();
    # get available language pairs:
    my %pairs = $engine->get_pairs();
    # default output format is 'plain_text'
    # change to 'marked_text':
    # check current output format:
    my $current_format = $engine->output_format();
    # configure a new Apertium object to store unknown words:
    my $engine = WWW::Translate::Apertium->new(
                                                output => 'marked_text',
                                                store_unknown => 1,
    # get unknown words for source language = Aranese
    my $es_unknown_href = $engine->get_unknown('oc_aran');


Apertium is an open source shallow-transfer machine translation engine designed to translate between related languages (and less related languages). It is being developed by the Department of Software and Computing Systems at the University of Alicante. The linguistic data is being developed by research teams from the University of Alicante, the University of Vigo and the Pompeu Fabra University. For more details, see

WWW::Translate::Apertium provides an object oriented interface to the Apertium online machine translation web service, based on Apertium 3.0.

Currently, Apertium supports the following language pairs:

- Bidirectional

- Single Direction



Creates and returns a new WWW::Translate::Apertium object.

    my $engine = WWW::Translate::Apertium->new();

WWW::Translate::Apertium recognizes the following parameters:

The default parameter values can be overridden when creating a new Apertium engine object:

    my %options = (
                    lang_pair => 'es-ca',
                    output => 'marked_text',
                    store_unknown => 1,

    my $engine = WWW::Translate::Apertium->new(%options);



Returns the translation of $string generated by Apertium, encoded as UTF-8. In case the server is down, the translate method will show a warning and return undef.

The input $string must be an UTF-8 encoded string (for this task you can use the Encode module or the PerlIO layer, if you are reading the text from a file).

If you are going to translate a string literal included in the code and then display the result in the output window of the code editor, then you should add the following statement to your code in order to avoid a "Wide character in print" warning:

    binmode(STDOUT, ':utf8');


Changes the engine language pair to $lang_pair. When called with no argument, it returns the value of the current engine language pair.


Returns a hash containing the available language pairs. The hash keys are the language codes, and the values are the corresponding language names.


Changes the engine output format to $format. When called with no argument, it returns the value of the current engine output format.


If the engine was configured to store unknown words, it returns a reference to a hash containing the unknown words (keys) detected during the current machine translation session for the specified source language, along with their frequencies (values).

The valid values of $lang_code for the source language are (in alphabetical order):








Apertium project website:

If you want to get the real thing, you can download the Apertium code and build it on your local machine. You will find detailed setup instructions in the Apertium wiki:


Many thanks to Mikel Forcada Zubizarreta, coordinator of the Transducens research team of the Department of Software and Computing Systems at the University of Alicante, who kindly answered my questions during the development of this module, and to Xavier Noria, João Albuquerque, and Kevin Brubeck Unhammer for useful suggestions. The author is also grateful to Francis Tyers, a member of the Apertium team who provided essential feedback for the latest versions of this module.


Enrique Nell, <blas.gordon at>


Please report any bugs or feature requests to bug-www-translate-apertium at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc WWW::Translate::Apertium

You can also look for information at:


Copyright (C) 2007-2010 by Enrique Nell, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.

syntax highlighting: