NAME
Microsoft::Translator - Client wrapper for Microsoft Translator's REST API
VERSION
version 0.001
SYNOPSIS
my $secret_key = 'Replace me with the key value in your instance details';
my $region = 'southcentralus';
my $tr = Microsoft::Translator->new( $secret_key, $region);
my @trans = $tr->translate([qq{Why hello there beautiful lady}], "en", qw{es});
foreach my $t (@trans) {
print "$t\n";
}
DESCRIPTION
Client module for the microsoft translator service, as described here: https://www.microsoft.com/en-us/translator/business/trial/ Follow the directions in the "Develop your own app" section in the page linked to get started.
In essence, you have to create an instance of Microsoft Translator on an Azure subscription in some region relevant to your application. You then will extract the "secret key" from said instance's "Resource" page under the "Keys and Endpoint" heading. Pass this and the region to the constructor.
Available regions for Azure are here: Azure Regions
Available languages for Microsoft Translator are here: Translator Languages
The various endpoints wrapped by this module are here: Translator REST API Endpoints
This module was developed against the 3.0 version of the API.
NAME
Microsoft::Translator
CONSTRUCTOR
new( STRING secret_key, STRING region, BOOL debug )
Returns an instance of Microsoft::Translator. Will print additional messages when the debug flag is high.
METHODS
translate( STRING[] $strings, STRING $source_language, ARRAY @target_languages)
Translate the provided ARRAYREF of strings which are of source_language to the provided ARRAY of target_languages.
Returns a HASHREF keyed by string and translated language. Example:
my $tr = Microsoft::Translator->new( $secret_key, $region);
my %trans = $tr->translate([qq{Hello beautiful lady}, qq{What time is it}], "en", qw{es fr});
print Data::Dumper::dumper(\%trans);
Would print:
$VAR1 = {
'Hello beautiful lady' => {
'fr' => 'Bonjour belle dame',
'es' => 'Hola hermosa dama'
},
'What time is it' => {
'es' => "Qu\x{e9} horas son",
'fr' => 'Quelle heure est-il'
}
};
Dies in the event that the HTTP request fails, or the source/target langs are not supported.
transliterate( STRING[] $strings, STRING $from_langugage, STRING $from_script, STRING $target_script )
Transliterate provided ARRAYREF of strings written in from_script to target_script. from_language is also needed, as a number of languages share scripts.
Example:
my $to_tl = [
"こんにちは",
"さようなら"
];
my $tr = Microsoft::Translator->new( $secret_key, $region);
my %tld = $tr->transliterate($to_tl, 'ja', 'Jpan', 'Latn');
print Dumper(\%tld);
Would print:
$VAR1 = {
'さようなら' => "\x{e3} \x{e3} \x{e3} \x{e3} \x{aa} \x{e3}",
'こんにちは' => "\x{e3} \x{e3} \x{e3} \x{ab} \x{e3} 0 \x{e3} \x{304}"
};
This obviously should be konnichiwa and sayonara, but I get:
ã ã ã « ã 0 ã ̄"
ã ã ã ã ª ã"
For whatever reason as of 10/2023. YMMV.
languages(STRING type)
Return ARRAY of supported language codes for the given type. Internally used to validate inputs, so you shouldn't need to call this during normal operations.
BUGS
Please report any bugs or feature requests on the bugtracker website https://github.com/Troglodyne-Internet-Widgets/Microsoft-Translator-Perl/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
AUTHORS
Current Maintainers:
George S. Baugh <teodesian@gmail.com>
COPYRIGHT AND LICENSE
Copyright (c) 2023 Troglodyne LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.