When submitting jobs from (local drupal) client to translators, language definitions can vary.

Instead of implementing a mapping feature per translator, we should introduce a general language mapping functionality.

This functionality is also relevant for the TMGMT Server.

Comments

blueminds’s picture

See the attached initial version

blueminds’s picture

Status: Active » Needs review
berdir’s picture

Looks good, some minor things:

+++ b/includes/tmgmt.plugin.incundefined
@@ -385,6 +445,81 @@ abstract class TMGMTDefaultTranslatorPluginController extends TMGMTPluginBase im
+    if (isset($translator->settings['remote_languages_mappings']) && is_array($translator->settings['remote_languages_mappings'])) {
+      $mappings = array_flip($translator->settings['remote_languages_mappings']);
+    }
+
+    if (isset($mappings[$language])) {
+      return $language;
+    }
+
+    $default_mappings = array_flip($this->getDefaultRemoteLanguagesMappings());

Instead of array_flip(), you could also use array_search(). Might be a bit simpler...

+++ b/tests/tmgmt_test.plugin.incundefined
@@ -57,6 +57,16 @@ class TMGMTTestTranslatorUIController extends TMGMTDefaultTranslatorUIController
+   * Overrides TMGMTDefaultTranslatorPluginController::getDefaultRemoteLanguagesMappings().
+   */
+  public function getDefaultRemoteLanguagesMappings() {
+    return array(
+      'en' => 'en-us',
+      'de' => 'de-ch',
+    );

It's a bit strange that the test translator defines default language mapping but does not implement it. But I'm not sure what to do with it instead.

+++ b/tests/tmgmt_test.plugin.incundefined
@@ -136,6 +146,14 @@ class TMGMTTestTranslatorPluginController extends TMGMTDefaultTranslatorPluginCo
+/**
+ * Class to tests remote languages mappings.
+ */
+class TMGMTTestTranslatorPluginControllerWithRemoteMapping extends TMGMTTestTranslatorPluginController {
+
+

Left-over?

+++ b/tmgmt.moduleundefined
@@ -1010,6 +1010,24 @@ function tmgmt_translator_labels_flagged($job = NULL) {
+/**
+ * Determines if the translator plugin supports remote language mappings.
+ *
+ * @param TMGMTTranslator $translator
+ *   Translator entity.
+ *
+ * @return bool
+ *   In case translator does not explicitly state that it does not provide the
+ *   mapping feature it will return TRUE.
+ */
+function tmgmt_provide_remote_languages_mappings(TMGMTTranslator $translator) {
+  if (!isset($translator->settings['map_remote_languages'])) {
+    return TRUE;
+  }
+
+  return $translator->settings['map_remote_languages'];

Why not make this a method on the translator?

+++ b/translators/file/tmgmt_file.format.incundefined
@@ -120,8 +127,8 @@ class TMGMTFileformatXLIFF extends XMLWriter implements TMGMTFileFormatInterface
+    $this->writeAttribute('source-language', $controller->mapToRemoteLanguage($translator, $job->source_language));
+    $this->writeAttribute('target-language', $controller->mapToRemoteLanguage($translator, $job->target_language));

We could simplify most usages of this by adding a helper method on the translator entity for this, then you just need to call $translator->mapToRemoteLanguage($job->source_language)).

blueminds’s picture

Status: Needs review » Needs work
StatusFileSize
new18.05 KB

It's a bit strange that the test translator defines default language mapping but does not implement it. But I'm not sure what to do with it instead.

Yes I agree, but not sure how to deal with it...

The rest is fixed.

blueminds’s picture

Status: Needs work » Needs review
berdir’s picture

Status: Needs review » Fixed

Thanks, commited.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

skyredwang’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs work

With 7.x-1.0-rc1, this is still broken. No matter what code I put in the Remote Languages Mapping, the $job->target_language still returns the original code set by Drupal. and getSupportedTargetLanguages returns the list provided by Translator.

I am trying to debug the problem of mapping.

skyredwang’s picture

Status: Needs work » Closed (fixed)

On IRC, @Berdir suggested I updated both tmgmt and tmgmt_google to the latest dev. then I can confirm that the problem is fixed.