Skip to content

Commit

Permalink
export txt without BOM
Browse files Browse the repository at this point in the history
  • Loading branch information
dtlnor committed Mar 16, 2023
1 parent 5901fa5 commit 3c98da9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions REMSGUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ def getEncoding(filename: str, bufferSize: int = 256*1024) -> str:
result = chardet.detect(rawdata)
encode = result['encoding']
confidence = result['confidence']
if encode is None or "ascii" == encode.lower() or (confidence < 0.9 and 'utf' not in encode.lower()):
if encode is None or "ascii" == encode.lower() or (confidence < 0.75 and 'utf' not in encode.lower()):
encode = 'utf-8'
if encode.lower() == 'utf-8':
encode = 'utf-8-sig'
return encode


Expand Down Expand Up @@ -222,7 +224,7 @@ def importCSV(msgObj: MSG, filename: str, version: int = None, langCount: int =
def exportTXT(msg: MSG, filename: str, lang: int):
"""write txt file from MSG object with specified language"""

with io.open(filename, "w", encoding="utf-8-sig") as txtf:
with io.open(filename, "w", encoding="utf-8") as txtf:
txtf.writelines(['<string>'+entry.langs[lang].replace('\r\n','<lf>')+'\n' for entry in msg.entrys])


Expand Down

0 comments on commit 3c98da9

Please sign in to comment.