Extracting comments from resx files

Hi all,

 

We have been translating resx files with the XML 2 file type and for the most part it has worked well so far. Only the text from the <value> tags is extracted for translation.

However, the customer has introduced a <comment> tag to the files now and we would like to have this information visible in Trados for the translators.

 

  <data name="0" xml:space="preserve">

    <value>Standard</value>

                <comment>Testkommentar</comment>

  </data>

 

This is what I tested so far:

I added a new rule and now the comments are visible in the editor. I could manually filter for “comment” tags and lock the segments.

Trados Studio rule editing dialog with XPath set to datacomment, properties set to translate Yes, and tag type Inline.

Trados Studio editor showing a segment with 'Standard' value and 'Testkommentar' comment, both highlighted in purple.

However, I would prefer to have the segments locked automatically. Would that be possible? I tried different settings, e.g. “Translation: No”, but apparently then the segments are not extracted at all.

 Trados Studio rule editing dialog with XPath set to datacomment, properties set to translate No, and tag type Inline.

Or is there another possibility to have the comments in Trados, e.g. as a Trados comment?

Trados version: 2019 SR2 15.2.8.3007

Thank you

Sara



Generated Image Alt-Text
[edited by: RWS Community AI at 8:17 AM (GMT 0) on 15 Nov 2024]
emoji
  •   

    Why not use the preview with a custom stylesheet?  Then you don't need to add a new parser rule at all and it's a lot cleaner and nicer to work with:

    Screenshot showing a custom preview created using a stylesheet.

    You didn't give us a complete file so I completed it like this (with some help from ChatGPT ;-))... saved as *.resx

    <?xml version="1.0" encoding="utf-8"?>
    <root>
      <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
        <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
        <xsd:element name="metadata">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="value" type="xsd:string" minOccurs="0" />
            </xsd:sequence>
            <xsd:attribute name="name" use="required" type="xsd:string" />
            <xsd:attribute name="type" type="xsd:string" />
            <xsd:attribute name="mimetype" type="xsd:string" />
            <xsd:attribute ref="xml:space" />
          </xsd:complexType>
        </xsd:element>
        <xsd:element name="assembly">
          <xsd:complexType>
            <xsd:attribute name="alias" type="xsd:string" />
            <xsd:attribute name="name" type="xsd:string" />
          </xsd:complexType>
        </xsd:element>
        <xsd:element name="data">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
              <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
            </xsd:sequence>
            <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
            <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
            <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
            <xsd:attribute ref="xml:space" />
          </xsd:complexType>
        </xsd:element>
        <xsd:element name="resheader">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
            </xsd:sequence>
            <xsd:attribute name="name" type="xsd:string" use="required" />
          </xsd:complexType>
        </xsd:element>
      </xsd:schema>
      <resheader name="resmimetype">
        <value>text/microsoft-resx</value>
      </resheader>
      <resheader name="version">
        <value>2.0</value>
      </resheader>
      <resheader name="reader">
        <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
      </resheader>
      <resheader name="writer">
        <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
      </resheader>
      <data name="0" xml:space="preserve">
        <value>Standard</value>
        <comment>Testkommentar</comment>
      </data>
    </root>

    Then I created a stylesheet like this... saved as *.xslt:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="html" indent="yes"/>
        
        <xsl:template match="/root">
            <html>
                <body>
                    <table border="1">
                        <tr>
                            <th>Name</th>
                            <th>Value</th>
                            <th>Comment</th>
                        </tr>
                        <xsl:apply-templates select="data"/>
                    </table>
                </body>
            </html>
        </xsl:template>
    
        <xsl:template match="data">
            <tr>
                <td><xsl:value-of select="@name"/></td>
                <td><xsl:value-of select="value"/></td>
                <td><xsl:value-of select="comment"/></td>
            </tr>
        </xsl:template>
    
    </xsl:stylesheet>

    Set the filetype settings like this:

    Screenshot showing how to add the stylesheet

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

    emoji
  • Hi Paul,

    Thank you for your explanation and for creating a style sheet. I got around to testing it now and with my Trados 2019 version it works great. This is a really clean solution.

    However, when I tried it with Trados 2021 on a different VM, it produces the “object reference not set to an instance of an object” error. I tested it with my own resx file and with the one you created, neither worked.

    When I delete the style sheet and use the standard preview, I get a syntax error, but after confirming, the xml preview is shown.

     Error dialog box in Trados Studio with a warning icon, indicating a script error at line 112, character 26, with the error message 'Syntax error' and code 0.

    Do I need a different style sheet for Trados 2021? That would be inconvenient because I would have to attach the style sheets individually for every translator. Or is there a general Trados setting that affects the style sheets?

     

    Sara

    emoji


    Generated Image Alt-Text
    [edited by: Trados AI at 11:58 AM (GMT 0) on 29 Feb 2024]
  •  

    It looks like it might be a bug. I can reproduce it in 2021 and 2022.  Good job you were using 2019 when you asked about this ;-)

    I have logged a ticket with the support team to check and see whether we already know about this or not: Case Details - 00811440

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

    emoji
  •   

    It seems there were changes made (that I don't fully understand yet) in 2021 onwards that require the stylesheet to have a header.  So, if you add the header like this (<head></head> before the <body> element):

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="html" indent="yes"/>
        
        <xsl:template match="/root">
            <html>
    		<head></head>
                <body>

    Your preview will work.  It should work in all versions too, so you'll only need one stylesheet for all your translators.

    See if that works for you?

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

    emoji
  •  

    We now have a KB article for this:

    https://gateway.sdl.com/apex/communityknowledge?articleName=000019668

    It seems Studio adds metadata to the html that is created to display the preview. It looks for the head element to add the metadata to it and if it's not there it throws the error.  Not too clever but at least we know why and it's simple to avoid.

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

    emoji