Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mbovan’s picture

Assigned: Unassigned » mbovan
Issue summary: View changes
Status: Active » Needs review
FileSize
5.99 KB

Here is the patch that provides XLIFF format support. It's depending on tmgmt_file module and recent changes made in #2646158: Support XLIFF export for a single job item.

Comment fixes from OHT feature: Add services based languages & language pairs list as well. :)

Berdir’s picture

Status: Needs review » Needs work

Nice.

  1. +++ b/tmgmt_oht.connector.inc
    @@ -233,10 +258,16 @@ class OHTConnector {
             'method' => 'POST',
    -        'data' => drupal_http_build_query($query),
           );
    +      // Support for multipart form data.
    +      if ($boundary) {
    +        $options['data'] = $this->multipartEncode($boundary, $query, $name);
    +      }
    +      else {
    +        $options['data'] = drupal_http_build_query($query);
    +      }
    

    what about changing it so data $query can either be an array or string. Possibly rename to $data. And then we call multipartEncode() ourself, pass that in and the only additional argument here is then the content_type. Might keep this simpler.

  2. +++ b/tmgmt_oht.connector.inc
    @@ -275,4 +306,36 @@ class OHTConnector {
    +   * @param $boundary
    +   *   The boundary.
    +   * @param $params
    +   *   The list of parameters.
    +   * @param int $name
    

    Add types everywhere. $name is also definitely not an int :)

  3. +++ b/tmgmt_oht.connector.inc
    @@ -275,4 +306,36 @@ class OHTConnector {
    +  public function multipartEncode($boundary, $params, $name) {
    +    $output = "";
    +    foreach ($params as $key => $value) {
    +      $output .= "--$boundary\r\n";
    +      // Support for keyword upload.
    +      if ($key == 'upload') {
    +        $output .= "Content-Disposition: form-data; name=\"$key\"; filename=\"$name\"\r\nContent-Type: text/plain\r\n\r\n";
    +        $output .= $value;
    

    This looks very generic, but it's actually hardcoded to having a single file named upload. With my changes suggested above, it might be simpler to just inline this into the new method instead of trying to be generic. We can refactor it later if we have more use cases for this.

mbovan’s picture

Status: Needs work » Needs review
FileSize
6.32 KB
5.41 KB

This patch should address all the points above.

Berdir’s picture

Status: Needs review » Needs work
  1. +++ b/tmgmt_oht.connector.inc
    @@ -198,22 +198,53 @@ class OHTConnector {
    +   * @param string $xlf
    +   *   XLF file to be translated.
    

    I'd use $xliff for this. Also clarify in the description that this is not a file but a string that we send as a file.

  2. +++ b/tmgmt_oht.connector.inc
    @@ -198,22 +198,53 @@ class OHTConnector {
    +    $output .= "Content-Disposition: form-data; name=\"upload\"; filename=\"$name.txt\"\r\nContent-Type: text/plain\r\n\r\n";
    
    +++ b/tmgmt_oht.plugin.inc
    @@ -179,7 +179,10 @@ class TMGMTOhtPluginController extends TMGMTDefaultTranslatorPluginController {
    +        $name = "JobID" . $job->tjid . '_JobItemID' . $job_item->tjiid . '_' . $job->source_language . '_' . $job->target_language;
    

    According to the documentation, this should end with .xliff.

mbovan’s picture

Status: Needs work » Needs review
FileSize
6.36 KB
1.28 KB

Missed #4.2 in documentation, sorry.

Berdir’s picture

Status: Needs review » Needs work
+++ b/tmgmt_oht.plugin.inc
@@ -179,7 +179,10 @@ class TMGMTOhtPluginController extends TMGMTDefaultTranslatorPluginController {
       foreach ($job->getItems() as $job_item) {
-        $oht_uuid = $this->getConnector($translator)->uploadTextResource($this->prepareDataForSending($job_item));

I think we can remove the old code here, at least prepareDataForSending().

I'm pretty sure you will also need to update import/parsing of the translation.

miro_dietiker’s picture

Just a quick note on required followups:
The XLIFF default converter can not handle HTML attributes that need translation such as alt, title. We need to make it aware of that.

mbovan’s picture

Status: Needs work » Needs review
FileSize
8.92 KB
2.71 KB

Removed prepareDataForSending(). Left it at first as I thought it might be needed in order to support both text resources and file resources.

Changed parsing function to support importing received XLIFF format based on #2646682: Update XLIFF to support string imports.

Also, fixed a small bug in configuration UI where an error appears if we don't have public/secret keys set.

Berdir’s picture

Status: Needs review » Fixed

Great, committed.

  • Berdir committed d359ff0 on 7.x-1.x authored by mbovan
    Issue #1971672 by mbovan: Switch to XLIFF format
    

  • Berdir committed d359ff0 on 8.x-1.x authored by mbovan
    Issue #1971672 by mbovan: Switch to XLIFF format
    

Status: Fixed » Closed (fixed)

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