Page 1 of 1

If I write in "Hebrew" in LIVECODE then the files I create go wrong

Posted: Sun May 01, 2022 3:29 pm
by liveCode
I ran this code:

Code: Select all

on mouseUp
         put  "שלום עולם" into url("file:" & $USERPROFILE&"\Documents\TEXT" & ".txt")
end mouseUp
The problem is that this is what comes out: a text file that says: ???? ????
What is the solution?

Re: If I write in "Hebrew" in LIVECODE then the files I create go wrong

Posted: Sun May 01, 2022 4:06 pm
by SparkOut
RTL languages might need some extra help, but first try with "binfile" instead of "file" after textEncoding the content as UTF-8.

I don't know if it will be the fix you need, but also you can check the BOM (Byte Order Marker) and charset for the file (ANSI / iso).

Some years ago I had to do some work with Farsi, where text files were created to be read by a telecaster for TV news ticker display. These required a BOM to prefix the binfile output of numToByte(239) numToByte(187) numToByte(191).

Re: If I write in "Hebrew" in LIVECODE then the files I create go wrong

Posted: Sun May 01, 2022 4:07 pm
by Klaus
Hi liveCode,

1. get used to the different specialfolderpath() names, they will work the same on ALL platforms. $USERPROFILE is Windows only!
2. get used to use the SLASH / as path-delimiter, LC uses this internally on ALL platforms.

You need to TEXTENCODE your text before writing to file:

Code: Select all

on mouseUp
   put textencode("שלום עולם","UTF-8") into url("file:" & specialfolderpath("documents") & "/TEXT.txt")
end mouseUp
And to TEXTDECODE when reading it in again:

Code: Select all

on mouseUp
   put url("file:" & specialfolderpath("documents") & "/TEXT.txt") into tText
   put textdecode(tText,"UTF-8") into fld 1
end mouseUp
Best

Klaus

Re: If I write in "Hebrew" in LIVECODE then the files I create go wrong

Posted: Sun May 01, 2022 8:05 pm
by richmond62
Personally I have found that all languages that don't use the Latin alphabet go wrong that way,
so I tend to export stuff to HTML:

Give this a try:

Code: Select all

on mouseUp
   ask file "Choose where you wish to export your text"
   if the result = "cancel" 
   then exit mouseUp
   else
      put the htmltext of fld "hTEXT" into url("file:" & it & ".html")
      set the itemDelimiter to slash
      set the defaultFolder to item 1 to -2 of the longFilePath of it
   end if
end mouseUp
-
SShot 2022-05-01 at 22.05.04.png

Re: If I write in "Hebrew" in LIVECODE then the files I create go wrong

Posted: Sun May 01, 2022 8:13 pm
by richmond62
My opinion of .txt files is pretty low, so when I don't feel I need HTML I favour .RTF:

Code: Select all

on mouseUp
   ask file "Choose where you wish to export your text"
   if the result = "cancel" 
   then exit mouseUp
   else
      put the RTFtext of fld "hTEXT" into url("file:" & it & ".rtf")
      get the longFilePath of it
      set the itemDelimiter to slash
      set the defaultFolder to item 1 to -2 of the longFilePath of it
   end if
end mouseUp

Re: If I write in "Hebrew" in LIVECODE then the files I create go wrong

Posted: Mon May 02, 2022 6:33 pm
by liveCode
Thanks you