Menu

#62 Basic error with latest LibreOffice on Linux

2.06
closed
None
1
2020-01-10
2020-01-09
No

It seems, on LibreOffice 6.x anaphraseus doesn't work. Its behaviour seems largely broken: After fininishing with the first segment, Anaphraseus tells me that there is nothing left to translate, thank you for working with Anaphraseus....
When I go on to select text manually and open it as a segment, half of the text disappears after closing it, and much of the preceding segment also goes away. From time to time I see runtime errors as the one below:

REM * BASIC ***
Option Explicit

'*****
' HideTranslation
' remove translation tables
'*****
Sub HideTranslation
Dim Dst As String
if SessionOpened() then Exit Sub

' show control codes
ControlCodes()

'On Error Goto Error_Label

' exit if translation segment is not opened
If NOT IsSegmentOpened() Then
MsgBox LMsg("SEGMNOP") 'L10N
Exit Sub
End If

' source or destination tables is broken or not exist
' oTableSrc, oTableDst - globals from TRBegin
If isTablesBroken() Then
MsgBox LMsg("SEGMBRK") 'L10N
Stage = STG_IDLE
Exit Sub
End If

if NOT isNull(SBar) then SBar.end() ' return of statusbar
if UseClipboard then
Dst = trim( CleanUpWClip() )
else
Dst = trim( CleanUp() )
endif

' new not empty translation
Dim mem, S() ,A() As string
If Dst<>"" AND UnSpecChar(TM_Dst)<>Dst Then
' old memory marking
If TM_Idx<>0 Then
S = Split(OFMemory(TM_Idx), Chr(9))
' mark memory with xx
S(0) = "xx"+mid(S(0),3)
OFMemory(TM_Idx) = Join(S, Chr(9))
Else
S = Split(Chr(9)+Chr(9)+"-1"+Chr(9)+Chr(9)+Chr(9)+Chr(9), Chr(9))
EndIf

' make timestamp - YYYYMMDD~HHMMSS
S(0) = CDateToISO(Now) + "~" + AddZero(Hour(Now)) + AddZero(Minute(Now)) + AddZero(Second(Now))
' get params from attributes (user initials)
A = Split(TMAttr(0), ",")
S(1) = A(1)
' version of TU -> + 1
S(2) = CStr( CInt(S(2)) + 1 )
' new fields
If TM_Idx=0 Then
S(3) = TMLSRC
S(4) = TM_Src
S(5) = TMLDST
EndIf
' new translation
S(6) = Dst
' get params from attributes
Dim i,n As Integer
n = UBound(TMAttr())
for i=1 to n
A = Split(TMAttr(i), ",")
if UBound(A())>0 then
Redim Preserve S(6+i)
S(6+i) = A(1)
endif
next i

' A = Split(TMAttr(2), ",")
' S(8) = A(1)

' OFIndex(NumTU) = TM_Src ' old code
' make new TU
mem = Join(S(), Chr(9))
if UseJava then

WriteTU(mem, TM_Idx)

' store translation to MyMemory server if required
if MyMemoryAPIKey<>"" then
MMSetQuery(TM_Src, Dst)
endif

If TM_Idx<>0 Then TMStorage.DelItem(TM_Src)

TMStorage.addTU(mem)
OFMemory = TMStorage.GetMemory()
OFMemorySrc = TMStorage.GetKeys()
OFIndex = TMStorage.GetIndexes()
NumTU = TMStorage.Size()

else
' NumTU + 1
NumTU = NumTU + 1
OFMemory(NumTU) = mem
OFMemorySrc(NumTU) = S(4)
' make position of new TU in TM file
if IsUnicode( TMEncoding ) then
OFIndex(NumTU) = OFIndex(NumTU-1) + (Len(OFMemory(NumTU-1))*2) + 4
else
if TMEncoding="UTF-8" then
OFIndex(NumTU) = OFIndex(NumTU-1) + UTF8Len( OFMemory(NumTU-1) )+ 2
else
OFIndex(NumTU) = OFIndex(NumTU-1) + Len( SpecChar( OFMemory(NumTU-1) ) )+ 2
endif
endif
' write new TU in file
WriteTU(OFMemory(NumTU), TM_Idx)

endif
End If

' change stage digit
'Stage = STG_SGMCLOSD
Exit Sub

' Error handler
Error_Label:
MsgBox LMsg("BASICERROR")+"HideTranslation:"+chr(10)+"'"+Error()+"'"+chr(10)+LMsg("BASICLINE")+Erl()
Stage = STG_SGMCLOSD
On Error Goto 0
End Sub

'-----------------------------------
' InsertMark - dumb function
' change style of string
'-----------------------------------
Sub InsertMark(S, Dir, Quan)
Dim oCurs, oSel As Object
oCurs = ThisComponent.getCurrentController().getViewCursor()
Select Case Dir
Case 0
oCurs.goLeft(Quan, True)
Case 1
oCurs.goRight(Quan, True)
End Select
ThisComponent.getCurrentSelection().getByIndex(0).setString("")
ThisComponent.Text.insertString(oCurs.getStart(), S, True)
oCurs.goLeft(Len(S),True)
oCurs.CharStyleName = "tw4winMark"
' oCurs.CharColor = RGB(128, 0, 128)
' oCurs.CharEscapement = -58
' oCurs.CharHidden = True
oCurs.goRight(Len(S),False)

End Sub

'-----------------------------------
' SetWFStyle
' set character style to special style
' in Cursor position
'-----------------------------------
Sub SetWFStyle(Cursor as object)
'for normal .CharEscapement = 0 .CharEscapementHeight = 100
'for superscript .CharEscapement = 33 .CharEscapementHeight = 58
'for subscript .CharEscapement = -101 .CharEscapementHeight = 58
' Cursor.ParaStyleName = "Standard"
Cursor.CharFontName = "Arial"
Cursor.CharColor = RGB(128, 0, 128)
Cursor.CharBackColor = -1
Cursor.CharUnderline = 0
Cursor.CharOverline = 0
Cursor.CharStrikeout = 0
Cursor.CharEscapement = -101
Cursor.CharEscapementHeight = 58
Cursor.CharHeight = 10
Cursor.CharFlash = False
Cursor.CharHidden = True
End sub

Sub SetOrigStyle(Cursor as object, optional isHidden as boolean)
if isMissing(isHidden) then isHidden = false
Cursor.CharColor = -1
Cursor.CharEscapement = 0
Cursor.CharEscapementHeight = 100
' Cursor.CharHeight = 10
Cursor.CharHidden = isHidden
End sub

'-----------------------------------
' UnSpecChar
' replace cpecial char code to char
'-----------------------------------
Function UnSpecChar(S) As String
Dim Ss, D, chk As String
Dim i, Dd As Long
D = ""
' destination string gets value of first char
Ss = Left(S, 1)
' loop to lenght of string
For I=2 To Len(S)
' if string contains special char mark
If Mid(S,i,2)="&'" Then
D = ""
' do collector work
Do
D = D + Mid(S, I, 1)
I = I + 1
Loop Until Mid(S, I, 1)=";"
' until meet mark of end (;)
D = D + ";"
' destination string updated by char code
chk = Mid(D,3,1) ' check if it tags or field here
if chk<>"t" AND chk<>"f" then Ss = Ss + HexToChar( D )
Else
' or by next char in charflow
Ss = Ss + Mid(S, I, 1)
End If
Next I
UnSpecChar = Ss
End Function

'-----------------------------------
' HexToChar
' return code of special char
'-----------------------------------
Function HexToChar(H) As String
Dim D As Long
' big case here
Select Case H
Case "&'26;"
D = 38
Case "&'82;"
D = 8218
Case "&'85;"
D = 8230
Case "&'91;"
D = 8216
Case "&'92;"
D = 8217
Case "&'93;"
D = 8220
Case "&'94;"
D = 8221
Case "&'96;"
D = 8211
Case "&'97;"
D = 8212
Case "&'99;"
D = 8482
Case "&'A0;"
D = 160
Case "&'AB;"
D = 171
Case "&'BB;"
D = 187
Case "&'1F;"
D = 31
Case "&'B;"
D = 11
Case Else
Dim val
val = Split(H(), "'") : val = Join (val, "H") ' Replace ' by H
val = Split(val, ";") : val = Join (val, "") ' Eliminate ;
D = CLng(val)
End Select
HexToChar = chr(D)
End Function

'-----------------------------------
' AddZero
' add leading zero to one byte string (for hour, minute, sec)
'-----------------------------------
Function AddZero(S) As String
if len(S)<2 Then S = "0" + S
AddZero = S
End Function

'-----------------------------------
' WriteTU
' write TU into TM file
'-----------------------------------
Sub WriteTU(S, I)
Dim v As Integer
Dim vv as Long
Dim sFileName As String
Dim n As Integer
Dim UnStr, Str, oFile

' TM file check
if isEmpty(TMFileName) OR TMFileName="" Then
MsgBox LMsg("MSGTREND1") 'L10N
Exit Sub
End If

v = 30840 ' ASCII xx
vv = 7864440 ' Unicode xx
sFileName = TMFileName
'S = S+chr(13)+chr(10)
Str = SpecChar(s)
n = FreeFile()
Open sFileName For Binary As #n
if Not IsUnicode( TMEncoding ) then
if TMEncoding<>"UTF-8" then Put #n, LOF(#n)+1, Str+chr(13)+chr(10)
If I<>0 Then Put #n, OFIndex(I), v
else
UnStr = Str2Uni(S+chr(13)+chr(10))
Put #n, LOF(#n)+1, UnStr
If I<>0 Then Put #n, OFIndex(I), vv
endif
Close #n
if TMEncoding="UTF-8" then
oFile = utf8OpenWrite(sFileName)
utf8WriteString(oFile, S+chr(13)+chr(10))
utf8CloseWrite(oFile)
endif
End Sub

Function CleanUp(Optional Flag As Boolean) As String
Dim FontName$, FontSize&, FontColor&, Dst, NumberingStyleName$, txt As String
Dim oText, oTable, oCurs, tCurs

' if true - clean table
If IsMissing(Flag) Then Flag = False

' get destination string from table
Dst = oTableDst.getCellByName("A1").getString()
if Dst=" " then Dst="" ' bugfix for Mac OpenOffice

' oTable = ThisComponent.TextTables.getByName("OF_Source") ' old things
TM_Src = oTableSrc.getCellByName("A1").getString()
' delete source table
ThisComponent.getCurrentController().select(oTableSrc)
oCurs = ThisComponent.getCurrentController().getViewCursor()
FontName = oCurs.CharFontName
FontSize = oCurs.CharHeight
FontColor = oCurs.CharColor
oTableSrc.dispose()

'create view cursor
' tCurs = oCurs.getText().createTextCursorByRange(oCurs.getStart())
' oCurs = ThisComponent.getCurrentController().getViewCursor()
oText = oCurs.getText()

' destination is empty - clean up
If Trim(Dst) = "" OR Flag Then
oCurs.goLeft(5, False)
NumberingStyleName = oCurs.NumberingStyleName
oCurs.goRight(5, True)
oCurs.setString("")
' ThisComponent.getCurrentSelection().getByIndex(0).setString("")
tCurs = oCurs.getText().createTextCursorByRange(oCurs.getStart())
Do ' go to segment delimiter
tCurs.goRight(1, True)
txt = tCurs.getString()
Loop Until Right(txt,2)="{>"
tCurs.CharHidden = False
tCurs.setString("")
' else remove unwanted CRs
Else
tCurs = oCurs.getText().createTextCursorByRange(oCurs.getStart())
tCurs.goLeft(1, True) : tCurs.setString("")
' ThisComponent.getCurrentSelection().getByIndex(0).setString("")
oCurs.goLeft(4, False)
NumberingStyleName = oCurs.NumberingStyleName
oCurs.goRight(1, False)
tCurs = oCurs.getText().createTextCursorByRange(oCurs.getStart())
tCurs.goLeft(1, True) : tCurs.setString("") ' to remove chr(13)
oCurs.goRight(3, True)
' matters of style (hide source)
oCurs.CharHidden = True
oCurs.goRight(1, False) : oCurs.goLeft(1, False)
End If
BulletsOff()
' Insert source text
oText.insertString(oCurs, chr(13), False)
' set locale
oCurs.CharLocale = LocaleFromTMX(TMLSRC, 0)
oCurs.CharHeight = FontSize
oCurs.CharFontName = FontName
oCurs.CharColor = FontColor
oCurs.CharEscapement = 0
oCurs.CharEscapementHeight = 100
oText.insertString(oCurs, TM_Src, False)
oCurs.goLeft(Len(TM_Src), False)
'UnoKey(".uno:GoToStartOfLine")
UnoKey(".uno:SwBackspace")

' matters of style (hide percents)
If Trim(Dst)<>"" AND Flag=false Then
tCurs = oCurs.getText().createTextCursorByRange(oCurs.getStart())
Do
tCurs.goRight(1, True)
oCurs.goRight(1, False)
txt = tCurs.getString()
Loop Until Right(txt,2)="{>"
tCurs.CharHidden = True
' oCurs.goRight(1, False) : oCurs.goLeft(1, False)
endif

' remove destinatoin table
ThisComponent.getCurrentController().select(oTableDst)
FontName = oCurs.CharFontName
FontSize = oCurs.CharHeight
FontColor = oCurs.CharColor
oTableDst.dispose()

' destination is empty - clean up
If Trim(Dst) = "" OR Flag Then
oCurs.goLeft(1, True)
ThisComponent.getCurrentSelection().getByIndex(0).setString("")
oCurs.goRight(4, True)
ThisComponent.getCurrentSelection().getByIndex(0).setString("")
' oCurs.goLeft(1, False)
' else remove of CRs
Else
tCurs = oCurs.getText().createTextCursorByRange(oCurs.getStart())
tCurs.goLeft(1, True) : tCurs.setString("")
' ThisComponent.getText().insertString(oCurs, Dst, False)

' Insert translated text
oText.insertString(oCurs, chr(13), False)
oCurs.goLeft(1, false)
oCurs.CharFontName = FontName
oCurs.CharHeight = FontSize
oCurs.CharColor = FontColor
oCurs.CharEscapement = 0
oCurs.CharEscapementHeight = 100
oText.insertString(oCurs, Dst, False)
oCurs.goRight(1, false)
UnoKey(".uno:SwBackspace")

 tCurs = oCurs.getText().createTextCursorByRange(oCurs.getStart())
 tCurs.goLeft(Len(Dst), True)
 tCurs.CharHidden = False
 ' set locale
 tCurs.CharLocale = LocaleFromTMX(TMLDST, 1)

 oCurs.goRight(3, False)
 tCurs = oCurs.getText().createTextCursorByRange(oCurs.getStart())
 tCurs.goRight(1, True) : tCurs.setString("")
 oCurs.goLeft(3, True)

' matters of style (hide ending)
oCurs.CharHidden = True
oCurs.goRight(1, False) : oCurs.goLeft(1, False)
End If
if NumberingStyleName<>"" then oCurs.NumberingStyleName = NumberingStyleName

CleanUp = Dst
End Function

Function CleanUpWClip(Optional Flag As Boolean) As String
Dim Dst$, txt$
Dim oText, oTable, oCurs, tCurs
Dim cCharHeight%, cUnderline%, cWeight%, cPosture&, cFontName$
Dim cBackColor&, cColor&, cEscapement%, cEscapementHeight%, cNumberingStyleName$

' if true - clean table
If IsMissing(Flag) Then Flag = False

oCurs = ThisComponent.getCurrentController().getViewCursor()

' get destination/source strings from table
Dst = oTableDst.getCellByName("A1").getString()
TM_Src = oTableSrc.getCellByName("A1").getString()
if Dst=" " then Dst="" ' bugfix for Mac OpenOffice

' select source table
ThisComponent.getCurrentController().select(oTableSrc)
oText = oTableSrc.getCellByName("A1").Text
if NumTerms>=0 then
UnMarkTerms( oText )
if CurTerm<>-1 then UnSelectTerm( CurTerm )
endif

' get font properties
cBackColor = oCurs.CharBackColor : cCharHeight = oCurs.CharHeight : cFontName = oCurs.CharFontName
cUnderline = oCurs.CharUnderline : cWeight = oCurs.CharWeight : cPosture = oCurs.CharPosture
cColor = oCurs.CharColor : cEscapement = oCurs.CharEscapement : cEscapementHeight = oCurs.CharEscapementHeight

oCurs.gotoEnd(True)
if trim(Dst)<>"" then oCurs.CharHidden = true ' turn hidden chars on if there is destination
UnoCut()
if trim(Dst) = "" OR flag then ' no translation, just close table
oCurs.goLeft(5, False)
cNumberingStyleName = oCurs.NumberingStyleName
oCurs.goRight(1, False)
UnoKey(".uno:SwBackspace")
oCurs.goRight(3, False)
UnoKey(".uno:SwBackspace") : UnoKey(".uno:SwBackspace"): UnoKey(".uno:SwBackspace")
' set font properties ================================================
oCurs.CharLocale = LocaleFromTMX(TMLSRC, 0)
oCurs.CharBackColor = cBackColor : oCurs.CharHeight = cCharHeight : oCurs.CharFontName = cFontName
oCurs.CharUnderline = cUnderline : oCurs.CharWeight = cWeight: oCurs.CharPosture = cPosture
oCurs.CharColor = cColor : oCurs.CharEscapement = cEscapement : oCurs.CharEscapementHeight = cEscapementHeight
oCurs.NumberingStyleName = cNumberingStyleName
UnoPaste()
else
' Here
oCurs.goLeft(5, False)
cNumberingStyleName = oCurs.NumberingStyleName
oCurs.goRight(1, False)

UnoKey(".uno:SwBackspace")
oCurs.goRight(3, False)
UnoKey(".uno:SwBackspace") : UnoKey(".uno:SwBackspace"): UnoKey(".uno:SwBackspace")
oCurs.NumberingStyleName = cNumberingStyleName
SetWFStyle(oCurs)

txt = "{0><}"+CStr(matchmetric)+"{> <0}"
oCurs.getText().insertString(oCurs.getEnd(), txt, False)
oCurs.goLeft(Len(txt)-3, False)
' oCurs.goRight(1, True)
' set font properties ================================================
SetOrigStyle(oCurs, true)
UnoPaste()
oCurs.goLeft(Len(TM_Src), true)
oCurs.CharLocale = LocaleFromTMX(TMLSRC, 0)
oCurs.CharBackColor = cBackColor : oCurs.CharHeight = cCharHeight : oCurs.CharFontName = cFontName
oCurs.CharUnderline = cUnderline : oCurs.CharWeight = cWeight: oCurs.CharPosture = cPosture
oCurs.CharColor = cColor : oCurs.CharEscapement = cEscapement : oCurs.CharEscapementHeight = cEscapementHeight
oCurs.goRight(Len(TM_Src), false)
' tCurs = oCurs.getText().createTextCursorByRange(oCurs.getStart()) ' dont need this
' tCurs.gotoStartOfParagraph(True)
' tCurs.CharHidden = true
' destination table
ThisComponent.getCurrentController().select(oTableDst)
' get font attributes
cBackColor = oCurs.CharBackColor : cCharHeight = oCurs.CharHeight : cFontName = oCurs.CharFontName
cUnderline = oCurs.CharUnderline : cWeight = oCurs.CharWeight : cPosture = oCurs.CharPosture
cColor = oCurs.CharColor : cEscapement = oCurs.CharEscapement : cEscapementHeight = oCurs.CharEscapementHeight

oCurs.gotoEnd(True)
UnoCut()
ThisComponent.getCurrentController().select(oTableSrc)
oCurs.goLeft(4, False)
oCurs.goLeft(1, True)
' set font properties ================================================
' set locale
oCurs.CharLocale = LocaleFromTMX(TMLDST, 0)
oCurs.CharBackColor = cBackColor : oCurs.CharHeight = cCharHeight : oCurs.CharFontName = cFontName
oCurs.CharUnderline = cUnderline : oCurs.CharWeight = cWeight: oCurs.CharPosture = cPosture
oCurs.CharColor = cColor : oCurs.CharEscapement = cEscapement : oCurs.CharEscapementHeight = cEscapementHeight
oCurs.CharHidden = false
UnoPaste()
endif
oTableSrc.dispose()
oTableDst.dispose()
if Dst<>"" AND Flag=false then oCurs.goRight(3, False)
oCurs.goDown(2, True)
oCurs.goRight(1, True)
UnoCut()
if Dst<>"" AND Flag=false then oCurs.goLeft(3, False)

'if NOT ShowHidden then
' ControlCodes(false)
' ThisComponent.getCurrentController().select(oTableDst)
' oCurs.goRight(1,False) : oCurs.goLeft(1,False)
'end if

CleanUpWClip = Dst
End Function

Discussion

  • Ole Yansen

    Ole Yansen - 2020-01-09

    Hi Johannes,

    For me it looks like old formatting problem we had with Libre Office.
    We even have entry in our FAQ

    Q. I have installed Anaphraseus to LibreOffice and it does not works!
    A. Please make sure hidden text is turned on. (Tools → Options → LibreOffice Writer → Formatting Aids: all 'hidden text' entries have to be checked on)

    Please check if this option is set in your config.

    With bes regards, Ole

     
    • Johannes Rohr

      Johannes Rohr - 2020-01-10

      Indeed, you made my day! Sorry for overlooking the FAQ, and keep up the good work!

       
      • Johannes Rohr

        Johannes Rohr - 2020-01-10

        One more thing: This should probably be added to the REAME that comes with the Anaphraseus zip, together with the information that LO 6.x is also supported. It currently says that OOo 4.x and LO 5.x are. I therefore concluded that maybe the error message is due to the fact that LO 6.x is not supported (which really made me sad!)

         
  • Ole Yansen

    Ole Yansen - 2020-01-10
    • status: open --> closed
    • assigned_to: Ole Yansen
     
  • Ole Yansen

    Ole Yansen - 2020-01-10

    I have added this information to the REAME that comes with the Anaphraseus zip.

    Regards, Oleg

     

Log in to post a comment.