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

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
liveCode
Posts: 119
Joined: Sun Oct 17, 2021 5:53 pm

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

Post by liveCode » Sun May 01, 2022 3:29 pm

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?

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

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

Post by SparkOut » Sun May 01, 2022 4:06 pm

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).

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

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

Post by Klaus » Sun May 01, 2022 4:07 pm

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

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

Post by richmond62 » Sun May 01, 2022 8:05 pm

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
Attachments
Hebrew.livecode.zip
Stack.
(1.04 KiB) Downloaded 66 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

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

Post by richmond62 » Sun May 01, 2022 8:13 pm

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

liveCode
Posts: 119
Joined: Sun Oct 17, 2021 5:53 pm

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

Post by liveCode » Mon May 02, 2022 6:33 pm

Thanks you

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”