cops/tools/export_file.txt
Sébastien Lucas 0787f6ead2 Update i18n from Calibre2Opds
If Excel 64Bits is used the following needs to be done :
Private Declare Function -> Private Declare PtrSafe Function
ByRef lpWideCharStr As Long -> ByRef lpWideCharStr As LongPtr
2012-11-30 09:06:07 +01:00

72 lines
2.8 KiB
Plaintext

' Output a file
' If there is no translation then we output the line as a comment
' that starts with #EN# indicating that translation is required
Sub Export_File(sType, iCol As Integer)
Dim oFile As Integer
Dim iRow As Integer
Dim iBlankLines As Integer
Dim sLangCode As String
Dim sOut As String
Dim sTemp As String
Dim bOut() As Byte
Dim shSheet As Worksheet: Set shSheet = Worksheets(sType)
sFilename = sType & "_" & LCase$(shSheet.Cells(cLanguageCodeRow, iCol).Value) & ".json"
oFile = FreeFile()
sFullPath = Application.ActiveWorkbook.Path & "\" & sFilename
On Error Resume Next
Kill sFullPath
Open sFullPath For Output As #oFile
Close #oFile
On Error GoTo 0
Open sFullPath For Binary Access Write As #oFile
' Output comment on version as first line
sOut = "{" & vbCrLf
bOut = UnicodeToBytes(Worksheets(cConfiguration).Cells(cOutputFormatRow, cOutputFormatCol), sOut)
Put #oFile, , bOut
iRow = cFirstDataRow
Do
sTemp = shSheet.Cells(iRow, cKeywordCol).Value
sOut = "// " & sTemp
' Print #oFile, sTemp;
If Len(sTemp) = 0 Then
iBlankLines = iBlankLines + 1
Else
iBlankLines = 0
If Not isComment(sTemp) And (Not (sTemp Like "config*") Or sTemp Like "config.Language*") And Not sTemp Like "gui*" And Not sTemp Like "error*" And Not sTemp Like "info*" And Not sTemp Like "stats*" Then
sOut = """" & sTemp & """" & ":"
' Print #oFile, "=";
sTemp = shSheet.Cells(iRow, iCol).Value
If Len(sTemp) > 0 Then
sOut = sOut & """" & sTemp & ""","
sOut = sOut & vbCrLf
bOut = UnicodeToBytes(Worksheets(cConfiguration).Cells(cOutputFormatRow, cOutputFormatCol), sOut)
Put #oFile, , bOut
' Print #oFile, sTemp;
Else
' If no language specific one supplied then
' output English one as a comment starting with '#EN#'
' (as long this is not the english column with empty value)
If iCol <> cEnglishLangCol Then
sOut = "// EN" & sOut
End If
sOut = sOut & shSheet.Cells(iRow, 3).Value
' Print #oFile, shSheet.Cells(iRow, 3).Value;
End If
End If
End If
' Print #oFile, "" ' Force new line
iRow = iRow + 1
Loop Until (iBlankLines > 5)
sOut = """fin"":""fin""" & vbCrLf & "}" & vbCrLf
bOut = UnicodeToBytes(Worksheets(cConfiguration).Cells(cOutputFormatRow, cOutputFormatCol), sOut)
Put #oFile, , bOut
Close #oFile
End Sub