javascriptthai

Merge Thai letters programmatically


I am trying to add Thai letters in HTMLInput value with javascript, but when I send each letter they are not combined together. For example, I am sending 'ท' and ' ี' and want to see 'ที', instead, I'm seeing 'ท ี'. They are not merging like 'ทืืืืืืื' they stand together like 'ท ื ื ื ื ื ื ื ื ื'.

I am taking Google Input Tools for example in this subject (https://www.google.com/inputtools/try/).

Any ideas would be very helpful. Thanks


Solution

  • The character is not a combination of and . The second character you have posted is a string of length 2. If you are copy-pasting from somewhere you've probably copied the space before it.

    console.log(" ี".length)
    
    console.log(
      Array.from(" ี", c => c.codePointAt(0))
    ) // [32, 3637]
    
    // 32 is for space

    The second character in ที a non-spacing mark . These non-spacing mark characters always combine with the character that precedes it. So, it's hard to copy them or write them as a literal.

    console.log(Array.from("ที")) // ['ท', 'ี']
    
    console.log("ี") // this is the second character, it's overlapping with "
    
    console.log(Array.from("ที", c => c.codePointAt(0))) // [3607, 3637]
    
    // string literal with Unicode escapes. 
    // 0e17 and 0e35 are hex for 3607, 3637
    console.log("\u0e17\u0e35") 

    If you want to paste it in an input, click on the Copy button on this page:

    https://unicode-table.com/en/0E35/