How to set html parser rule to translate or NOT translate text in span elements based on the value of an attribute (data-condition)? The html code is generated by RoboHelp. [Conditional text]

<p class="Numbered" dir="ltr">Click to place the object in the drawing.<span data-condition="VW:Comment"> [Test of conditional text for translation.]</span></p>

Parents
  • Maybe something like this as your condition:

    span[@data-condition="VW:Comment"]

    Then set it as non-translatable:

    Trados Studio Edit Rule window showing a rule setup with condition span@data-condition='VW:Comment' and properties set to non-translatable.

    I created this file to test:

    <!DOCTYPE html>
    <html>
    <body>
    
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span data-condition="VW:Comment">Don’t translate me</span></p>
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span>Translate me</span></p>
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span data-condition="VW:Comment">Don’t translate me either</span></p>
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span>Do me too</span></p>
    
    </body>
    </html>

    And it extracts like this:

    Trados Studio preview pane displaying extracted text from an HTML file with specific spans marked as 'Don t translate me' set as non-translatable.

    So seems to work for me anyway.

    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



    Generated Image Alt-Text
    [edited by: Trados AI at 9:41 AM (GMT 0) on 29 Feb 2024]
  • Hi Paul,

    Thank you for your prompt reply to my post. I had gone that far and wasn't clear in my question.

    What I'm trying to configure are multiple conditions for the same attribute with different conditions values.

    For example:

    data-condition="condition_1" then DO NOT TRANSLATE

    data-condition="condition_2" then DO NOT TRANSLATE

    data-condition="condition-3" then DO NOT TRANSLATE

    ELSE TRANSLATE 

    Thanks

  • Why don't you provide a sample file with just the bits you need?  Asking a question like this and expecting someone else to do all the work may prevent you getting a timely response.

    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

  • ok

    I used this test file:

    <!DOCTYPE html>
    <html>
    <body>
    
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span data-condition="condition_1">Don’t translate condition 1</span></p>
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span>Translate me</span></p>
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span data-condition="condition_2">Don’t translate condition 2</span></p>
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span>Do me too</span></p>
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span data-condition="condition_3">Don’t translate condition 3</span></p>
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span>And don’t forget me</span></p>
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span data-condition="condition_4">Condition 4 or any other condition is just fine for translation</span></p>
    
    </body>
    </html>

    First I tried this which I believe should work as it is valid xpath 1.0:

    span[@data-condition="condition_1" or @data-condition="condition_2" or @data-condition="condition_3"]

    But it doesn't.  So I did this instead:

    Trados Studio error message showing 'span' elements with 'data-condition' attributes 'condition_1', 'condition_2', and 'condition_3' marked as 'Not Translatable'.

    Just duplicate the rule we created first and use whatever attribute values you need.  Gave me this:

    Trados Studio preview pane displaying HTML content with instructions to click and place objects, including 'span' elements with translation conditions.

    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


    Generated Image Alt-Text
    [edited by: Trados AI at 9:42 AM (GMT 0) on 29 Feb 2024]
Reply
  • ok

    I used this test file:

    <!DOCTYPE html>
    <html>
    <body>
    
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span data-condition="condition_1">Don’t translate condition 1</span></p>
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span>Translate me</span></p>
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span data-condition="condition_2">Don’t translate condition 2</span></p>
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span>Do me too</span></p>
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span data-condition="condition_3">Don’t translate condition 3</span></p>
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span>And don’t forget me</span></p>
    <p class="Numbered" dir="ltr">Click to place the object in the drawing.<span data-condition="condition_4">Condition 4 or any other condition is just fine for translation</span></p>
    
    </body>
    </html>

    First I tried this which I believe should work as it is valid xpath 1.0:

    span[@data-condition="condition_1" or @data-condition="condition_2" or @data-condition="condition_3"]

    But it doesn't.  So I did this instead:

    Trados Studio error message showing 'span' elements with 'data-condition' attributes 'condition_1', 'condition_2', and 'condition_3' marked as 'Not Translatable'.

    Just duplicate the rule we created first and use whatever attribute values you need.  Gave me this:

    Trados Studio preview pane displaying HTML content with instructions to click and place objects, including 'span' elements with translation conditions.

    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


    Generated Image Alt-Text
    [edited by: Trados AI at 9:42 AM (GMT 0) on 29 Feb 2024]
Children