Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Solved, with the help of macro's author!
* After inserting ~/.config/libreoffice/4/user/Scripts/python/TradutorLibreText.py
* and after installing libreoffice-script-provider-python

This is now my macro

sub translate_word
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Language"
args1(0).Value = "Current_Italian (Italy)"

dispatcher.executeDispatch(document, ".uno:LanguageStatus", "", 0, args1())

rem--nuovo inserim inizio
    Dim oScriptProvider, oScript
    oScriptProvider = ThisComponent.getScriptProvider()
    oScript = oScriptProvider.getScript("vnd.sun.star.script:TradutorLibreText.py$TradutorLibreText?language=Python&location=user")
    oScript.invoke(array(), array(), array())
rem--nuovo inserim fine
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:WordLeftSel", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Undo", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Undo", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:GoToEndOfLine", "", 0, Array())

rem ----------------------------------------------------------------------
dim args7(0) as new com.sun.star.beans.PropertyValue
args7(0).Name = "Text"
args7(0).Value = " "

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args7())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())

rem ----------------------------------------------------------------------
dim args9(0) as new com.sun.star.beans.PropertyValue
args9(0).Name = "Text"
args9(0).Value = ")"

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args9())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:GoToPrevWord", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:GoToPrevWord", "", 0, Array())

rem ----------------------------------------------------------------------
dim args12(0) as new com.sun.star.beans.PropertyValue
args12(0).Name = "Text"
args12(0).Value = "("

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args12())

rem ----------------------------------------------------------------------
dim args13(1) as new com.sun.star.beans.PropertyValue
args13(0).Name = "Count"
args13(0).Value = 1
args13(1).Name = "Select"
args13(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args13())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:WordRightSel", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:WordRightSel", "", 0, Array())

rem ----------------------------------------------------------------------
dim args16(1) as new com.sun.star.beans.PropertyValue
args16(0).Name = "Count"
args16(0).Value = 1
args16(1).Name = "Select"
args16(1).Value = true

dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args16())

rem ----------------------------------------------------------------------
dim args17(0) as new com.sun.star.beans.PropertyValue
args17(0).Name = "Color"
args17(0).Value = 8421504

dispatcher.executeDispatch(document, ".uno:Color", "", 0, args17())

rem ----------------------------------------------------------------------
dim args18(2) as new com.sun.star.beans.PropertyValue
args18(0).Name = "FontHeight.Height"
args18(0).Value = 8
args18(1).Name = "FontHeight.Prop"
args18(1).Value = 100
args18(2).Name = "FontHeight.Diff"
args18(2).Value = 0

dispatcher.executeDispatch(document, ".uno:FontHeight", "", 0, args18())

end sub

Solved, with the help of macro's author!
* After inserting ~/.config/libreoffice/4/user/Scripts/python/TradutorLibreText.py
* and after installing libreoffice-script-provider-python

This is now my macro

sub translate_word
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Language"
"Language"
args1(0).Value = "Current_Italian (Italy)"

dispatcher.executeDispatch(document, ".uno:LanguageStatus", "", "Current_Italian (Italy)"

dispatcher.executeDispatch(document, ".uno:LanguageStatus", "", 0, args1())

rem--nuovo inserim inizio
    Dim oScriptProvider, oScript
    oScriptProvider = ThisComponent.getScriptProvider()
    oScript = oScriptProvider.getScript("vnd.sun.star.script:TradutorLibreText.py$TradutorLibreText?language=Python&location=user")
oScriptProvider.getScript("vnd.sun.star.script:TradutorLibreText.py$TradutorLibreText?language=Python&location=user")
    oScript.invoke(array(), array(), array())
rem--nuovo inserim fine
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:WordLeftSel", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Undo", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Undo", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:GoToEndOfLine", "", ".uno:WordLeftSel", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Undo", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Undo", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:GoToEndOfLine", "", 0, Array())

rem ----------------------------------------------------------------------
dim args7(0) as new com.sun.star.beans.PropertyValue
args7(0).Name = "Text"
"Text"
args7(0).Value = " "

dispatcher.executeDispatch(document, ".uno:InsertText", "", " "

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args7())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "", ".uno:Paste", "", 0, Array())

rem ----------------------------------------------------------------------
dim args9(0) as new com.sun.star.beans.PropertyValue
args9(0).Name = "Text"
"Text"
args9(0).Value = ")"

dispatcher.executeDispatch(document, ".uno:InsertText", "", ")"

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args9())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:GoToPrevWord", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:GoToPrevWord", "", ".uno:GoToPrevWord", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:GoToPrevWord", "", 0, Array())

rem ----------------------------------------------------------------------
dim args12(0) as new com.sun.star.beans.PropertyValue
args12(0).Name = "Text"
"Text"
args12(0).Value = "("

dispatcher.executeDispatch(document, ".uno:InsertText", "", "("

dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args12())

rem ----------------------------------------------------------------------
dim args13(1) as new com.sun.star.beans.PropertyValue
args13(0).Name = "Count"
"Count"
args13(0).Value = 1
args13(1).Name = "Select"
"Select"
args13(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoLeft", "", ".uno:GoLeft", "", 0, args13())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:WordRightSel", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:WordRightSel", "", ".uno:WordRightSel", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:WordRightSel", "", 0, Array())

rem ----------------------------------------------------------------------
dim args16(1) as new com.sun.star.beans.PropertyValue
args16(0).Name = "Count"
"Count"
args16(0).Value = 1
args16(1).Name = "Select"
"Select"
args16(1).Value = true

dispatcher.executeDispatch(document, ".uno:GoRight", "", ".uno:GoRight", "", 0, args16())

rem ----------------------------------------------------------------------
dim args17(0) as new com.sun.star.beans.PropertyValue
args17(0).Name = "Color"
"Color"
args17(0).Value = 8421504

dispatcher.executeDispatch(document, ".uno:Color", "", ".uno:Color", "", 0, args17())

rem ----------------------------------------------------------------------
dim args18(2) as new com.sun.star.beans.PropertyValue
args18(0).Name = "FontHeight.Height"
"FontHeight.Height"
args18(0).Value = 8
args18(1).Name = "FontHeight.Prop"
"FontHeight.Prop"
args18(1).Value = 100
args18(2).Name = "FontHeight.Diff"
"FontHeight.Diff"
args18(2).Value = 0

dispatcher.executeDispatch(document, ".uno:FontHeight", "", ".uno:FontHeight", "", 0, args18())

end sub