Problem/Motivation

When working with XLIFF files, some translation providers work by processing the target attributes only and replacing those with real/translated values.

Proposed resolution

Use plugin configuration to allow Xliff plugin to react based on target setting.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

mbovan created an issue. See original summary.

berdir’s picture

We didn't do it for the previous change of supporting reading from strings but I think this is a perfect use case for using plugin configurations and passing it to getInstance().

This is specific to XLIFF and does not need to result in a change on the data we accept/return.

There have been discussions in the past about also supporting to send an existing translation. While we don't have the API in place for that yet on Job/JobItem/data level, we could already prepare for it by not making it a bool but support multiple values, e.g. 'target' => empty|source|existing_translation or something like that (for now just the first two)

Also wondering about test coverage, we probably want to expose that setting in the file translator too. We could go all the way with configurable/form plugins and embed the selected plugin configuration inside the translator settings. Or we just special case that setting for now. But we could already store the configuration so that we can expand it, e.g. 'format_configuration' => ['translate' => 'source'].

mbovan’s picture

Issue summary: View changes

Updated the proposed resolution.

mbovan’s picture

Status: Active » Needs review
StatusFileSize
new8.24 KB

Updated File translator Xliff implementation as suggested in #2.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/translators/tmgmt_file/config/schema/tmgmt_file.schema.yml
    @@ -16,3 +16,9 @@ tmgmt.translator.settings.file:
    +      sequence:
    +        type: string
    +        label: Single format configuration option
    

    this isn't a sequence, it is a map of specific keys.

  2. +++ b/translators/tmgmt_file/src/FileTranslatorUi.php
    @@ -29,27 +29,45 @@ class FileTranslatorUi extends TranslatorPluginUiBase {
    +    $form['format_configuration']['target'] = [
    +      '#type' => 'select',
    +      '#title' => t('Target translation data'),
    +      '#options' => [
    +        'source' => t('Same as source'),
    +      ],
    +      '#empty_option' => t('Empty'),
    +      '#default_value' => $translator->getSetting('format_configuration.target'),
    +      '#description' => t('Fill the target translation data.'),
    

    title: Target content
    description: Defines what the <target> in the XLIFF file should contain, either empty or the same as the source text.

  3. +++ b/translators/tmgmt_file/src/Plugin/tmgmt_file/Format/Xliff.php
    @@ -69,6 +69,20 @@ class Xliff extends \XMLWriter implements FormatInterface {
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function __construct(array $configuration, $plugin_id, $plugin_definition) {
    +    $this->configuration = $configuration;
    +  }
    

    inheritdoc is wrong because this doesn't implement an interface, so we need a "Creates Xliff instance + params docblock"

  4. +++ b/translators/tmgmt_file/src/Plugin/tmgmt_file/Format/Xliff.php
    @@ -141,6 +146,29 @@ class Xliff extends \XMLWriter implements FormatInterface {
    +  /**
    +   * Helper function to write the data.
    +   *
    

    "Helper function" is IMHO a useless prefix, just write what it does: "Writes text according to the XLIFF export settings." ?

mbovan’s picture

Status: Needs work » Needs review
StatusFileSize
new8.61 KB
new2.72 KB

Thanks for the review.

Addressed all the points.

berdir’s picture

Status: Needs review » Needs work
+++ b/translators/tmgmt_file/src/FileTranslatorUi.php
@@ -38,13 +38,13 @@ class FileTranslatorUi extends TranslatorPluginUiBase {
       '#default_value' => $translator->getSetting('format_configuration.target'),
-      '#description' => t('Fill the target translation data.'),
+      '#description' => t('Defines what the <target> in the XLIFF file should contain, either empty or the same as the source text.'),
     ] + $xliff_states;

It wasn't visible in my text, but I actually escaped the tag so it is actually visible as one in the description.. this will not actually be visible I think :)

mbovan’s picture

Status: Needs work » Needs review
StatusFileSize
new8.61 KB
new788 bytes

Yes, you are right. :)

  • Berdir committed 79e051d on 8.x-1.x authored by mbovan
    Issue #2973057 by mbovan: Populate the target content with source in...
berdir’s picture

Status: Needs review » Fixed

Committed, thanks.

Status: Fixed » Closed (fixed)

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