For static text is it very easy, but you need to specify languages from and to.
But this approach is very vulnerable. When somebody change anything in the text, this method can't translate it.
Better approach is to use some "textId" stored in LeaderNote attributes. Then user can specify this textId (select from list of corresponding texts) and then you store this id to attributes. When you start translation, you just read this textId and from target dictionary select appropriate text.
Sub Main
Dim drawing As DrawingDocument = ThisDoc.Document
Dim activeSheet As Sheet = drawing.ActiveSheet
For Each oLeaderNote As LeaderNote In activeSheet.DrawingNotes.LeaderNotes
Dim oldText = oLeaderNote.FormattedText
Dim newText = Translate(oldText, "en", "es")
If newText IsNot Nothing Then
oLeaderNote.FormattedText = newText
End If
Next
End Sub
Dim enDictionary As New List(Of String)({
"EN description"
})
Dim esDictionary As New List(Of String)({
"ES descripción"
})
Dim deDictionary As New List(Of String)({
"DE Beschreibung"
})
Function Translate(oldText As String, fromLang As String, toLang As String) As String
Dim fromDictionary = GetDictionary(fromLang)
Dim toDictionary = GetDictionary(toLang)
Dim i = fromDictionary.IndexOf(oldText)
If i >= 0 Then
Return toDictionary(i)
Else
Return Nothing
End If
End Function
Function GetDictionary(lang As String) As List(Of String)
Select Case lang
Case "en"
Return enDictionary
Case "es"
Return esDictionary
Case "de"
Return deDictionary
Case Else
Return Nothing
End Select
End Function