.Net Parser Comments

Hi

I'm using the .Net Parser to perform an English review process on RESX files. So the generated files are still source files.

The resulting RESX files generated (making sure the "write only changed" option is unticked) and stored back in source control and used for product builds.

The original RESX files have lots of really useful comments that the parser handles very nicely.

However, the generated target RESX files lose the comments.

Meaning: 

1) When I do a DIFF of the original file versus the Passolo generated file, I get tons of hits due to comments missing on the target files.

2) I cannot simply commit the Passolo generated files into source control. I'll lose those helpful comments for next time.

My question is, is there a way to keep the comments. An option in the .Net Parser Settings dialog to "Keep source file comments" would be nice to have :-)

 

Thanks

Mark

  • Hi Mark,

    I know that writing comments (in the source) into the target RESX is not possible in Passolo. A simple workaround would be to use a tool such as Beyond Compare and merge the comments back in. It's quite straightforward and fast to do so (10 seconds a file?), but if you have hundreds of RESX files, that might become more time-consuming that you would like.

    You can always provide your feedback in Ideas place, but I am not sure how you would justify such needs. It is nice to have indeed.

    Thanks,
    Naoko
  • Hi Naoko,
    Thanks for replying.

    It's a strange omission in my opinion, given that they are XML files.But I guess that, because the same parser is used for binary assemblies too, RESX files aren't treated as XML?

    To give me the file I need after after generation I might have to consider using an XML parser instead. I've just done a quick "round-trip" test and compared the generated file with the original and they are the same (apart from the parts I "translated").
    Thanks,
    Mark
  • Some additional comments:

    The fact that the comments are missing in the translated RESX files is related to the method how the files are written. The .NET parser is using internal .NET Framework classes like ResXResourceReader and ResXResourceWriter. In previous versions of the .NET Framework, these classes doesn’t offer the ability to write back the comment into the RESX files. This is why this wasn’t implemented in the past.

    On the other side, what usually happens to a translated RESX files? It is compiled into a satellite assembly where the comments are deleted anyway. So no real need to write back the comments when they will be deleted later in the process.

    So the real use cases where the comments need to be written to the translated RESX files are rather rare. As the above classes now allow the comment to be written back, the enhancement was logged into the developers ticket system, but it’s up to product management, if and when this requirement will be implemented.

    There are multiple temporary work arounds

    • You already outlined one of the solution. Write a small XML parsing rule and use XML parser to handle the files. Please be aware that this only works properly for RESX files with StringTable resources. In WinForm RESX files there is a lot other information stored that is used by Passolo to create a visual view of the dialog. This data will also pop up as a translatable item when you use the XML parser.
    • You could potentially implement a system macro that automatically opens the translated RESX file generated by Passolo and inserts all the comments from the project. Please be aware when doing this for WinForm files. The next time Visual Studio is opening this RESX file the comments will be deleted.

    At the end I would not recommend to use any text file comparison tool to migrate the comments from source to target. The fact that the Passolo .NET Parser is writing the RESX files using .NET Framework classes has another ugly side effect. The order in which the string entries are stored in the RESX files can differ from source to target and will not have the same order as the source file. The order is determined by a rather  unknown hashing algorithm within the .NET Framework that is calculating the hash code from the translated string.

  • Hi Achim,
    Yes I agree my use case is rare, but I've had really good results using Passolo as an English Review tool. It offers the reviewer a much better experience than diffing files in a source control tool.

    Luckily the RESX files for the specific product only use string tables, but I also note your warning over the ordering of the resulting files.
    Thanks
    Mark
  • In case of StringTable resources only you can use the attached XML parsing rule that I once created for another client. Using this rule for StringTable RESX files will preserve the comments and the order in the translated files.

    <?xml version="1.0" encoding="UTF-16"?>
    <CXMLRules>
      <RuleList>
        <CXMLRule m_strName="RESX Files" m_bResolveExternal="False">
          <RootElements>
            <RootElement Name="root"/>
          </RootElements>
          <ResTypes/>
          <RuleData>
            <CXMLData ElementName="value" IDAttributeName="../attribute::name" TElementName="" IsTElement="False" HandlingOfWhiteSpaces="0" HandlingOfEmbeddedElements="0" AppendElementNameToID="False" UseSegmenter="False">
              <Attributes>
                <CXMLAttribute AttributeName="../comment" CopyAttributeName="False" AttributeAction="5"/>
              </Attributes>
            </CXMLData>
          </RuleData>
        </CXMLRule>
      </RuleList>
    </CXMLRules>
    

    Download the file, rename it to xfg extension and import it into the XML parser settings dialog.