Adept icon indicating copy to clipboard operation
Adept copied to clipboard

UTF8/16 /Unicode to proper manange asian charactors

Open LukyGuyLucky opened this issue 1 year ago • 4 comments

Thanks for the great lanaguage!

I would like to read/write asain charaters(files) with this lanaguage either with GUIs or in terminals under Windows 10 64 bit.Is it possible ?

Thanks and best regards.

LukyGuyLucky avatar May 06 '24 02:05 LukyGuyLucky

Keep your source files in UTF-8 (without BOM) and type the Unicode characters as normal. I think it will work.

ghost avatar May 06 '24 09:05 ghost

@LukyGuyLucky Yes as iahung2 described, even though it isn't officially supported, you can sometimes get away with just putting it in the text.

If you want to be sure though, you can use embed to include file contents at compile-time as a String, and then use them like normal:

asian.txt

汉字山한글乇乂丅尺卂たくさんあったけれど時間ることができ

main.adept

import basics

foreign SetConsoleOutputCP(uint) int
define CP_UTF8 = 65001

func main {
    #if __windows__
    SetConsoleOutputCP(CP_UTF8)
    #end

    text String = embed "asian.txt"
    print(text)
}

https://github.com/IsaacShelton/AdeptAsianText

IsaacShelton avatar May 06 '24 16:05 IsaacShelton

Thanks both.It works.

But when the text filename is with ansia charactor say 汉字.txt,then the program will fail to read.

LukyGuyLucky avatar May 09 '24 09:05 LukyGuyLucky

Yes, using non-ascii characters in the code itself is not officially supported

Since Windows uses a different encoding scheme for filenames, that's why it does not work on Windows. (I tried cross-compiling it to Windows from macOS and works, so this is specific to the Windows filesystem)

main.adept:12:19: error: Failed to read file '汉字.txt'
  12|     text String = embed "汉字.txt"
                        ^^^^^

Feel free to make a PR though if you like

Also, this issue will be taken care of and non-latin characters will be fully supported in Adept 3.0 once it comes

IsaacShelton avatar May 09 '24 18:05 IsaacShelton