webui-dev / webui

Use any web browser or WebView as GUI, with your preferred language in the backend and modern web technologies in the frontend, all in a lightweight portable library.
https://webui.me
MIT License
2.9k stars 164 forks source link

Unicode Support #188

Closed hassandraga closed 11 months ago

hassandraga commented 1 year ago

WebUI does not support Unicode right now. If the local file name, HTML content or any string is encoded in a multi-byte format like UTF8, it won't show proper characters in most cases. We can update all WebUI APIs from char* to wchar_t* beside all the needed core changes. This will make WebUI support Unicode.

If we did this, some wrappers probably need updates to make strings multi-byte instead of one-byte format (ASCII). Before I process this, I would like to know your thoughts.

V Unicode Nim Unicode TypeScript Unicode Python Unicode Pascal Unicode Go Unicode

ttytm commented 11 months ago

❤️ Would be great to have, even essential for some apps!

ttytm commented 11 months ago

Coming back to this. What kind of use-case would this serve?

#include "webui.h"

int main() {
    size_t my_window = webui_new_window();
    webui_show(my_window, "<html><head><script src=\"webui.js\"></script></head>Hello 👋!</html>");
    webui_wait();
    return 0;
}

While the window for the code above would contain: Hello 👋!

#include "webui.h"

int main() {
  size_t my_window = webui_new_window();
  webui_show(my_window, "<html><head><meta charset=\"UTF-8\"><script "
                        "src=\"webui.js\"></script></head>Hello 👋!</html>");
  webui_wait();
  return 0;
}

Just specifying the html charset is enough to correctly display Hello 👋!

fibodevy commented 11 months ago

Works

pQwDb096wu

hassandraga commented 11 months ago

Sorry, I wasn't clear enough in my comment. I know that. That's why I added Unicode Test in examples a while ago. https://github.com/webui-dev/webui/blob/6a634cc680fd7cf0511536ab7302274991489412/examples/C/serve_a_folder/index.html#L50C15-L50C15

<p>
            Unicode Test:<br><br>
            مرحبًا<br> <!-- Arabic -->
            你好<br> <!-- Chinese -->
            こんにちは <!-- Japanese -->
        </p>

I mean by supporting Unicode in WebUI is to make library able to handl Unicode files name and paths. This webui_show(win, "/home/ちは/test/こん.html") won't works right now.

ttytm commented 11 months ago

I see, so it's an issue regarding accessibility and internationalisation.

hassandraga commented 11 months ago

Implemented (https://github.com/webui-dev/webui/commit/42c6e22c4903443e7aa7728bafcbb22b277c55e8).

hassandraga commented 11 months ago

FYI: No wrapper changes are needed.