How to display or conveniently reference String ID inside an xliff file in Trados Studio 2022?

A customer's source file format is bilingual xliff file containing English and Traditional Chinese contents, which also contains string IDs. The customer wants to import these String IDs into Trados Studio to help translators reference them during translation. Do we have a viable solution or some best practices that can help? Please see the sample below.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xliff version="1.2" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<file build-num="4102" datatype="x-android-res" date="2023/10/16 18:19:38" original="sample" source-language="en-US" target-language="zh-TW">
<body>
<trans-unit app-name="sample" db-id="119853" id="string:STRING_AddressBook_Chat_Delete_Chat" src-path="\\Git\sample\string.xml">
<origin>Delete chat</origin>
<source xml:space="preserve">Delete chat</source><target state="needs-translation">刪除聊天</target>
</trans-unit>
<trans-unit app-name="sample" db-id="119854" id="string:STRING_AddressBook_Chat_Delete_Chat_Warning" src-path="\\Git\sample\string.xml">
<origin>Are you sure you want to delete this chat?</origin>
<source xml:space="preserve">Are you sure you want to delete this chat?</source><target state="needs-translation">您確定要刪除此聊天嗎?</target>
</trans-unit>
<trans-unit app-name="sample" db-id="119855" id="string:STRING_AddressBook_Chat_Dialog_Group_Already_Exists_Cancel_Btn" src-path="\\Git\sample\string.xml">
<origin>Cancel</origin>
<source xml:space="preserve">Cancel</source><target state="translated">取消</target>
</trans-unit>
<trans-unit app-name="sample" db-id="119881" id="string:STRING_AddressBook_Chat_Members_Selected" src-path="\\Git\sample\string.xml">
<origin>{0} members selected</origin>
<source xml:space="preserve">{0} members selected</source><target state="needs-translation">已選擇 {0} 位成員</target>
</trans-unit>
<trans-unit app-name="sample" db-id="119882" id="string:STRING_AddressBook_Chat_Message_Btn" src-path="\\Git\sample\string.xml">
<origin>Message</origin>
<source xml:space="preserve">Message</source><target state="translated">訊息</target>
</trans-unit>

</body>
</file>

</xliff>



Question... not discussion.
[edited by: Paul at 4:42 PM (GMT 1) on 25 Oct 2023]
  •  

    I think you won't be able to do this.  If you had the original resource file that was used to create the XLIFF in the firs place then it may well have been possible and you could have used the DSI Viewer to make this convenient.  But as the file is already an XLIFF the only way I can think to handle this directly in Studio would be as a custom XML filetype, but then you would not have the benefit of any existing translations.

    I guess a workaround would be to extract the content into Excel, translate the Excel and then update the XLIFF with the translations afterwards.  For example, this Excel VBA macro could create the Excel from your file:

    Sub ImportXLIFF()
        Dim ws As Worksheet
        Dim lastRow As Long
        Dim xliffPath As String
        Dim xmlDoc As Object
        Dim xmlNodeList As Object
        Dim xmlNode As Object
        Dim i As Long
        
        ' Set the worksheet where data will be written
        Set ws = ThisWorkbook.Sheets("Sheet1")
        
        ' Ask the user to paste the path to the XLIFF file
        xliffPath = InputBox("Paste the full path to the XLIFF file:", "Select XLIFF File")
        
        ' Check if path is empty
        If xliffPath = "" Then
            MsgBox "No path provided, exiting macro."
            Exit Sub
        End If
        
        ' Initialize XML objects
        Set xmlDoc = CreateObject("MSXML2.DOMDocument.6.0")
        
        ' Load XLIFF into XML document
        xmlDoc.async = False
        xmlDoc.Load (xliffPath)
        
        If xmlDoc.parseError.ErrorCode <> 0 Then
            MsgBox "XML Parse Error: " & xmlDoc.parseError.reason
            Exit Sub
        End If
        
        ' Set the header row
        ws.Cells(1, 1).Value = "ID"
        ws.Cells(1, 2).Value = "Source Content"
        ws.Cells(1, 3).Value = "Target Content"
        ws.Cells(1, 4).Value = "App Name"
        ws.Cells(1, 5).Value = "DB ID"
        
        ' Get list of trans-unit nodes
        Set xmlNodeList = xmlDoc.SelectNodes("//trans-unit")
        
        ' Loop through each trans-unit node and extract ID, Source, and Target
        i = 2 ' Starting from row 2 as row 1 has headers
        For Each xmlNode In xmlNodeList
            ws.Cells(i, 1).Value = xmlNode.getAttribute("id")
            ws.Cells(i, 2).Value = xmlNode.SelectSingleNode("source").Text
            ws.Cells(i, 3).Value = xmlNode.SelectSingleNode("target").Text
            ws.Cells(i, 4).Value = xmlNode.getAttribute("app-name")
            ws.Cells(i, 5).Value = xmlNode.getAttribute("db-id")
            i = i + 1
        Next xmlNode
        
        MsgBox "XLIFF data imported successfully!"
    End Sub

    Gets you this:

    Alt-text: The image displays a spreadsheet with five columns labelled A to E. The first row contains column headers: "ID", "Source Content", "Target Content", "App Name", and "DB ID". Rows 2 to 6 show data entries. The entries in the "A" column appear to be string identifiers for chat-related functions, such as deleting a chat or sending a message. The "B" column contains English descriptions of these functions like "Delete chat" and "Are you sure you want to delete this chat?". The "C" column provides translations of the English descriptions into an East Asian language. The "D" column consistently lists "sample" as the app name for each entry, and the "E" column provides unique database ID numbers for each row.

    You can easily handle this with the Bilingual Excel filetype and see the additional attributes as comments or document structure information.

    Then either pre-translate the original XLIFF from your TM, or insert any updated targets from the Excel using another macro.  For example:

    Sub UpdateXLIFFFromExcel()
        Dim ws As Worksheet
        Dim lastRow As Long
        Dim xliffPath As String
        Dim xmlDoc As Object
        Dim xmlNodeList As Object
        Dim xmlNode As Object
        Dim i As Long
        Dim idVal As String
        Dim dbIdVal As String
        Dim targetVal As String
        
        ' Set the worksheet where data will be read from
        Set ws = ThisWorkbook.Sheets("Sheet1")
        
        ' Find the last row in the Excel sheet
        lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
        
        ' Ask the user to paste the path to the original XLIFF file
        xliffPath = InputBox("Paste the full path to the original XLIFF file:", "Select XLIFF File")
        
        ' Check if path is empty
        If xliffPath = "" Then
            MsgBox "No path provided, exiting macro."
            Exit Sub
        End If
        
        ' Initialize XML objects
        Set xmlDoc = CreateObject("MSXML2.DOMDocument.6.0")
        
        ' Load the original XLIFF into the XML document
        xmlDoc.async = False
        xmlDoc.Load (xliffPath)
        
        If xmlDoc.parseError.ErrorCode <> 0 Then
            MsgBox "XML Parse Error: " & xmlDoc.parseError.reason
            Exit Sub
        End If
        
        ' Loop through each row in Excel, starting from row 2
        For i = 2 To lastRow
            idVal = ws.Cells(i, 1).Value
            dbIdVal = ws.Cells(i, 5).Value
            targetVal = ws.Cells(i, 3).Value
            
            ' Search for the corresponding 'trans-unit' node in XLIFF by matching 'ID' and 'DB-ID'
            Set xmlNode = xmlDoc.SelectSingleNode("//trans-unit[@id='" & idVal & "' and @db-id='" & dbIdVal & "']")
            
            ' If the corresponding 'trans-unit' is found, update its 'target' child node
            If Not xmlNode Is Nothing Then
                xmlNode.SelectSingleNode("target").Text = targetVal
            End If
        Next i
        
        ' Save the updated XLIFF back to the original file
        xmlDoc.Save xliffPath
        
        MsgBox "XLIFF updated successfully!"
    End Sub

    Add this into your target Excel file, run it and select the original XLIFF file.  The macro will update the target content in the XIFF from your Excel file by comparing the ID and DB-ID attributes to identify the matching trans-unit elements. Seems to work for me with this very simple test... but I'd advise you to test thoroughly f you decide to take this approach.

    Maybe some ideas 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

    emoji
  • Thank you  , I tested the macro and it worked for me too. Sorry for late feedback and thank you again!

    emoji