diff -Nuar xc/lib/X11/imThaiFlt.c xc.thaiutf8/lib/X11/imThaiFlt.c
--- xc/lib/X11/imThaiFlt.c	2002-07-28 20:29:24.000000000 +0700
+++ xc.thaiutf8/lib/X11/imThaiFlt.c	2002-07-28 20:31:03.000000000 +0700
@@ -1221,7 +1221,7 @@
 {
     Xic		    ic = (Xic)client_data;
     KeySym 	    symbol;
-    int 	    count;
+    int 	    wcount;
     int 	    isc_mode; /* Thai Input Sequence Check mode */
     unsigned char   previous_char; /* Last inputted Thai char */
 #if 0
@@ -1229,8 +1229,9 @@
     KeySym	    lsym,usym;
     int		    state;
     XicThaiPart     *thai_part;
-#endif
     char	    buf[10];
+#endif
+    wchar_t	    wbuf[10];
     int	            i;
 
     if ((ev->type != KeyPress)
@@ -1239,7 +1240,8 @@
 
     if (!IC_IscMode(ic)) InitIscMode(ic);
 
-    count = XmbLookupString((XIC)ic, &ev->xkey, buf, sizeof(buf), &symbol, NULL);
+    wcount = XwcLookupString((XIC)ic, &ev->xkey,
+                            wbuf, sizeof(wbuf)/sizeof(wbuf[0]), &symbol, NULL);
 
     if ((ev->xkey.state & (AllMods & ~ShiftMask)) ||
          ((symbol >> 8 == 0xFF) &&
@@ -1303,24 +1305,26 @@
      */
     isc_mode = IC_IscMode(ic);
     if (!(previous_char = IC_GetPreviousChar(ic))) previous_char = ' ';
-    if (!THAI_isaccepted(buf[0], previous_char, isc_mode)) {
+    if (!THAI_isaccepted(ucs2tis(wbuf[0]), previous_char, isc_mode)) {
         /* reject character */
         XBell(ev->xkey.display, BellVolume);
         return True;
     }
     /* Remember the last character inputted. */
-    IC_SavePreviousChar(ic, buf[count-1]);
-    for (i=0; i<count; i++)
-        ic->private.local.composed->mb[i] = buf[i];
-    ic->private.local.composed->mb[count] = '\0';
+    IC_SavePreviousChar(ic, ucs2tis(wbuf[wcount-1]));
+    for (i=0; i<wcount; i++)
+        ic->private.local.composed->wc[i] = wbuf[i];
+    ic->private.local.composed->wc[wcount] = '\0';
 
-    _Xlcmbstowcs(ic->core.im->core.lcd, ic->private.local.composed->wc,
-		 ic->private.local.composed->mb, count);
+    _Xlcwcstombs(ic->core.im->core.lcd, ic->private.local.composed->mb,
+		 ic->private.local.composed->wc, 10);
 
     _Xlcmbstoutf8(ic->core.im->core.lcd, ic->private.local.composed->utf8,
-		  ic->private.local.composed->mb, count);
+		  ic->private.local.composed->mb, 10);
 
-    if (!((buf[0] > 0 && buf[0] <= 0x1f) || (buf[0] == 0) || (buf[0] == 0x7f)))
+    previous_char = ucs2tis(wbuf[0]);
+    if (!((previous_char > 0 && previous_char <= 0x1f) ||
+          (previous_char == 0) || (previous_char == 0x7f)))
         ic->private.local.composed->keysym = NoSymbol;
     else
         ic->private.local.composed->keysym = symbol;
diff -Nuar xc/nls/locale.dir xc.thaiutf8/nls/locale.dir
--- xc/nls/locale.dir	2002-07-22 21:50:11.000000000 +0700
+++ xc.thaiutf8/nls/locale.dir	2002-07-22 21:54:55.000000000 +0700
@@ -348,7 +348,7 @@
 en_US.UTF-8/XLC_LOCALE:			sv_SE.UTF-8
 en_US.UTF-8/XLC_LOCALE:			ta_IN.UTF-8
 en_US.UTF-8/XLC_LOCALE:			tg_TJ.UTF-8
-en_US.UTF-8/XLC_LOCALE:			th_TH.UTF-8
+th_TH.UTF-8/XLC_LOCALE:			th_TH.UTF-8
 en_US.UTF-8/XLC_LOCALE:			tl_PH.UTF-8
 en_US.UTF-8/XLC_LOCALE:			tr_TR.UTF-8
 en_US.UTF-8/XLC_LOCALE:			tt_RU.UTF-8
diff -Nuar xc/nls/XI18N_OBJS/Imakefile xc.thaiutf8/nls/XI18N_OBJS/Imakefile
--- xc/nls/XI18N_OBJS/Imakefile	2002-07-22 21:50:11.000000000 +0700
+++ xc.thaiutf8/nls/XI18N_OBJS/Imakefile	2002-07-22 21:52:15.000000000 +0700
@@ -65,6 +65,7 @@
 XI18NTarget(zh_TW.big5)
 XI18NTarget(th_TH)
 XI18NTarget(en_US.UTF-8)
+XI18NTarget(th_TH.UTF-8)
 #ifdef UXPArchitecture
 XI18NTarget(ja.U90)
 XI18NTarget(ja.S90)
diff -Nuar xc/nls/XI18N_OBJS/th_TH.UTF-8 xc.thaiutf8/nls/XI18N_OBJS/th_TH.UTF-8
--- xc/nls/XI18N_OBJS/th_TH.UTF-8	1970-01-01 07:00:00.000000000 +0700
+++ xc.thaiutf8/nls/XI18N_OBJS/th_TH.UTF-8	2002-07-22 21:51:44.000000000 +0700
@@ -0,0 +1,7 @@
+# CATEGORY(XLC|XIM|OM)	SHARED_LIBRARY_NAME	FUNCTION_NAME
+#
+#	XI18N objects table for th_TH.UTF-8 locale
+#
+XLC	common/xlcUTF8Load	_XlcUtf8Loader	# XLC_open
+XIM	common/ximcp	_XimOpenIM _XimRegisterIMInstantiateCallback  _XimUnRegisterIMInstantiateCallback # XIM_open	XIM_register XIM_unregister
+XOM	common/xomGeneric 	_XomGenericOpenOM	# XOM_open
diff -Nuar xc/nls/XLC_LOCALE/Imakefile xc.thaiutf8/nls/XLC_LOCALE/Imakefile
--- xc/nls/XLC_LOCALE/Imakefile	2002-07-22 21:50:11.000000000 +0700
+++ xc.thaiutf8/nls/XLC_LOCALE/Imakefile	2002-07-22 21:54:22.000000000 +0700
@@ -77,6 +77,7 @@
 LTarget(zh_TW.big5)
 LTarget(th_TH)
 LTarget(en_US.UTF-8)
+LTarget(th_TH.UTF-8)
 #ifdef UXPArchitecture
 LTarget(ja.U90)
 LTarget(ja.S90)
diff -Nuar xc/nls/XLC_LOCALE/th_TH.UTF-8 xc.thaiutf8/nls/XLC_LOCALE/th_TH.UTF-8
--- xc/nls/XLC_LOCALE/th_TH.UTF-8	1970-01-01 07:00:00.000000000 +0700
+++ xc.thaiutf8/nls/XLC_LOCALE/th_TH.UTF-8	2002-07-22 21:53:55.000000000 +0700
@@ -0,0 +1,75 @@
+# $XConsortium: th_TH$
+# XLocale Database Sample for th_TH
+#
+# $XFree86:$
+#
+# Modified from origial th_TH.TACTIS
+
+# 
+# 	XLC_FONTSET category
+# 
+XLC_FONTSET
+#	fs0 class
+fs0	{
+	charset	{
+		name	ISO10646-1
+	}
+	font	{
+		primary	ISO10646-1
+	}
+}
+#	We leave the legacy encodings in for the moment, because we don't
+#	have that many ISO10646 fonts yet.
+# 	fs0 class (7 bit ASCII)
+fs1	{
+	charset		ISO8859-1:GL
+	font            ISO8859-1:GL
+}
+# 	fs1 class (Thai) 
+fs2	{
+	charset         TIS620-0:GR
+	font            TIS620-0:GR
+}
+END XLC_FONTSET
+
+# 
+# 	XLC_XLOCALE category
+# 
+XLC_XLOCALE
+
+encoding_name           UTF-8
+mb_cur_max		3
+state_depend_encoding	False
+
+
+wc_encoding_mask	\x30000000
+wc_shift_bits		7
+
+
+
+
+
+
+use_stdc_env            True
+force_convert_to_mb     True
+
+
+# 	cs0 class
+cs0	{
+	side		GL:Default
+	length		1
+	wc_encoding	\x00000000
+	ct_encoding     ISO8859-1:GL
+}
+
+
+# 	cs1 class
+cs1	{
+	side		GR:Default
+	length		1
+
+	wc_encoding	\x30000000
+	ct_encoding     TIS620-0:GR
+}
+
+END XLC_XLOCALE
