Issues with FileMappingRules

Issue #2 resolved
John Lindahl created an issue

Edit: Please see my PR for suggested fix.

If I give the following zanata.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config xmlns="http://zanata.org/namespace/config/">
  <url>http://whatever.url.com</url>
  <project>second</project>
  <project-version>0.0.1</project-version>
  <!-- NB project-type set to 'podir' to allow offline translations to be
       uploaded, but original was 'gettext' -->
  <project-type>podir</project-type>
  <src-dir>untranslated</src-dir>
  <trans-dir>translated</trans-dir>
  <rules>
    <rule pattern="**/*.po">{path}/{filename}.{locale}.po</rule>
    <rule pattern="**/*.pot">{path}/{filename}.{locale}.{extension}</rule>
  </rules>

</config>

And add a console.log(this.resource) after https://bitbucket.org/tagoh/zanata-js/src/3a7a8c9982594c4070208c928ad30fe0fd94c1e8/lib/zanata/config.js?at=master&fileviewer=file-view-default#config.js-42

The output will be:

this.Resource {
  "config": {
    "xmlns": "http://zanata.org/namespace/config/",
    "url": "http://lab-zanata.dev.nordnet.se:8080/zanata/",
    "project": "second",
    "project-version": "0.0.1",
    "project-type": "podir",
    "src-dir": "untranslated",
    "trans-dir": "translated",
    "rules": {
      "rule": [
        {
          "pattern": "**/*.po",
          "$t": "{path}/{filename}.{locale}.po"
        },
        {
          "pattern": "**/*.pot",
          "$t": "{path}/{filename}.{locale}.{extension}"
        }
      ]
    }
  }
}

Please take a good look at rules.rule which is show quite a behaviour. I suspect the expected outcome should be something along the lines of:

"rules": [
      {
      "rule": {
          "pattern": "**/*.po",
          "$t": "{path}/{filename}.{locale}.po"
        },
     },
      "rule":  {
          "pattern": "**/*.pot",
          "$t": "{path}/{filename}.{locale}.{extension}"
        },
     }
      ]
    ]

Comments (7)

  1. Akira TAGOH repo owner

    Hm, well, that is how xml2json behaves on converting the xml document to JSON. maybe good to request a fix there if needed though, is there any concerns or any real harm on current behavior?

  2. John Lindahl reporter

    It actually breaks and I am not able to use my mappings. I had to add the following after https://bitbucket.org/tagoh/zanata-js/src/3a7a8c9982594c4070208c928ad30fe0fd94c1e8/lib/zanata/config.js?at=master&fileviewer=file-view-default#config.js-42

    if(this.resource.config && this.resource.config.rules && !Array.isArray(this.resource.config.rules)) {
           const rules = this.resource.config.rules;
           this.resource.config.rules = rules.rule.map(function(rule){ return {rule:rule}; });
         }
    

    The reason is that some code (I think it was here: https://bitbucket.org/tagoh/zanata-js/src/3a7a8c9982594c4070208c928ad30fe0fd94c1e8/lib/zanata/fileMapping.js?at=master&fileviewer=file-view-default#fileMapping.js-86) assumes that the rules has the "correct" format.

  3. Log in to comment