Using Thai in the program

I am currently working on a super short program which just takes a one word string input (in Thai) and then pass on the python program which has been written. I have a problem with dealing with Thai text. everything from inputing it to displaying it. Anyone has an idea if processing supports Thai or not or anything I can do.

Ps. I have tried enabling complext text input in the program but it does not seem to work for Thai

1 Like

Hi, @sts10m!

I think things should work if you do some small things: indicate strings are Unicode if you use Thai text in the code, string literals, like hello_text = u"āļŠāļ§āļąāļŠāļ”āļĩ" (note the u before the "). Because this is Jython/Python 2â€Ķ Otherwise you could use, first thing in your sketch:

from __future__ import unicode_literals

Get Processing to select an appropriate font for drawing, maybe like this:

def setup():
    size(400, 400)
    thai_font = createFont('Noto-Sans-Thai.ttf', 24)  # put TTF file inside sketch/data/ folder
    textFont(thai_font)

def draw():
    text(u'āļŠāļ§āļąāļŠāļ”āļĩ', 100, 100)

If you use multiple tabs, beware the other .py files need to start with this “magic” comment:
# -*- coding: utf-8 -*-

What other inputs do you need? Keyboard or reading text files?

Keyboard input in Processing is one key at a timeâ€Ķ if Thai script needs key combinations to interact, I’m not sure it would be able to capture those interactions, maybe a dialog window to get the whole word could help?

def input(question='', suggestion=''):   # Processing Python mode does not have the built-in input()!!!
    from javax.swing import JOptionPane
    return JOptionPane.showInputDialog(None, question, suggestion)

Let us know if any of this works!

Good luck with your projects!

3 Likes