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>

  • 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:

    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:

    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]
  • Works like a charm! Thank you.

    emoji
  • Hi guys,

    A similar question: is there a way to say "Translatable" based on certain conditions? Like <code> would always be "Not Translatable", except when its "class = c1". 

    Trados Studio Edit Rule window showing an incorrect attribute condition for 'code class=c1' with a red box highlighting 'has not value' error. Text editor in Trados Studio with multiple 'code' tags, some with class 'c1' highlighted, and a comment questioning why subtraction here when the imaginary component increases as we go up.

    I solved the problem manipulating the XML. 

    But I wonder if wouldn't be a more simple way to do this.

    Thank you all!

    emoji


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