I am working with a Drupal 7 site that offers multiple variants of English (en-us, en-au, etc.), and Brazillian Portuguese (pt-br). All source content is en-us.
One of our translation providers (Sovee) uses the language-code-plus-country-code convention of specifying source and target languages (such as "Translate en-us to pt-br"). Other translation providers (such as Google Translate) requires the two-letter versions (such as "Translate en to pt")
In /admin/config/regional/tmgmt_translator/manage/google I have specified the Google Remote languages mappings as:
"remote_languages_mappings" : {
"en-us" : "en",
"pt-br" : "pt",
"en-ca" : "en",
"de" : "de",
"es" : "es",
"fr" : "fr",
"ru" : "ru",
"en-gb" : "en",
"en-au" : "en",
"el" : "el",
"en" : "en",
"nn" : "nn",
"sv" : "sv",
"tr" : "tr"
}
However, the Google Translate plugin does not appear to be honoring those mappings.
As a test, I modified tmgmt_google.plugin.inc , and hard-coded the source language to be "en"
protected function googleRequestTranslation(TMGMTJob $job, $q) {
return $this->doRequest($job->getTranslator(), 'translate', array(
// 'source' => $job->source_language,
'source' => 'en',
'target' => $job->target_language,
$this->qParamName => $q,
), array(
'headers' => array(
'Content-Type' => 'text/plain',
),
));
}
and added 'en-us' and 'pt-br' to the $languages array:
public function getSupportedTargetLanguages(TMGMTTranslator $translator, $source_language) {
$languages = array();
try {
$request = $this->doRequest($translator, 'languages');
foreach ($request['data']['languages'] as $language) {
$languages[$language['language']] = $language['language'];
}
}
catch (TMGMTGoogleException $e) {
watchdog_exception('tmgmt', $e, 'Unable to retrieve a list of available languages.');
}
// My code below.
watchdog('langs', 'languages=<pre>' . print_r($languages, TRUE) . '</pre>');
$languages['en-us'] = 'en';
$languages['pt-br'] = 'pt';
return $languages;
}
This "hack" does the trick, and allows the Google Translator to translate our source (en-us) documents to Portuguese (pt-br) -- but (other than quick tests) I'd really rather not modify a contrib module.
Is there a better way to get the translations to work for us?
(I also tried the patch at https://www.drupal.org/node/1999994 -- it did not address this issue.)
Comments
Comment #2
charlesj CreditAttribution: charlesj commented