hangul_ic_get_keyboard_name()의 리턴값을 로캘에 관계없이 UTF-8로 함
authorChoe Hwanjin <choe.hwanjin@gmail.com>
Wed, 29 Dec 2010 14:30:34 +0000 (23:30 +0900)
committerChoe Hwanjin <choe.hwanjin@gmail.com>
Wed, 29 Dec 2010 14:30:34 +0000 (23:30 +0900)
hangul_ic_get_keyboard_name() 함수의 리턴값을 사용하는 곳의 대부분이
UTF-8인 경우에 더 사용하기 편리하다. nabi, ibus, scim, imhangul 등의 경우
결국 스트링을 UTF-8로 변환해야 하므로 여기에서 UTF-8을 리턴하면 코딩이
더 편리해진다. 단 tools/hangul.c 에서는 locale에 따른 변환을 해주어야
하므로 약간 더 불편해지기는 하지만, 나머지에서 수정할 내용이 줄어들므로
이 편이 더 낫다.

git-svn-id: http://kldp.net/svn/hangul/libhangul/trunk@252 8f00fcd2-89fc-0310-932e-b01be5b65e01

configure.ac
hangul/hangulinputcontext.c
tools/hangul.c

index d8bb0fd..d8f622c 100644 (file)
@@ -27,6 +27,7 @@ AC_PROG_INSTALL
 # Checks for header files.
 AC_HEADER_STDC
 AC_CHECK_HEADERS([stdlib.h string.h limits.h])
+AC_CHECK_HEADERS([langinfo.h])
 
 # Checks for typedefs, structures, and compiler characteristics.
 AC_HEADER_STDBOOL
@@ -41,6 +42,7 @@ AC_FUNC_MMAP
 AC_FUNC_REALLOC
 AC_CHECK_FUNCS([munmap])
 AC_CHECK_FUNCS([strcasecmp])
+AC_CHECK_FUNCS([nl_langinfo])
 
 # Checks for gettext stuff
 GETTEXT_PACKAGE="$PACKAGE"
index 8f472d6..d112263 100644 (file)
@@ -1842,6 +1842,7 @@ hangul_ic_get_keyboard_name(unsigned index_)
     if (!isGettextInitialized) {
        isGettextInitialized = true;
        bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
+       bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
     }
 #endif
 
index 9fe6bf3..7d8057f 100644 (file)
 #include <getopt.h>
 #include <errno.h>
 
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
+
 #include <iconv.h>
 
 #include "../hangul/hangul.h"
@@ -98,6 +102,24 @@ list_keyboards()
     unsigned n;
 
     n = hangul_ic_get_n_keyboards();
+
+#if defined(ENABLE_NLS) && defined(HAVE_NL_LANGINFO)
+    if (n > 0) {
+       // hangul_ic_get_keyboard_name() 함수가 UTF-8 스트링으로 리턴하므로
+       // 여기서는 locale 인코딩으로 변환해야 한다.
+       // 그런데 iconv를 호출하여 변환하기가 번거로우므로
+       // bind_textdomain_codeset을 다시 호출하여 gettext가 리턴하는 스트링의
+       // 인코딩을 바꿔준다. 이렇게 하기 위해서는
+       // hangul_ic_get_keyboard_name()을 먼저 호출하여
+       // bind_textdomain_codeset() 함수가 불린후 다시 설정하도록 한다.
+       const char* codeset = nl_langinfo(CODESET);
+       if (codeset != NULL) {
+           hangul_ic_get_keyboard_name(0);
+           bind_textdomain_codeset(GETTEXT_PACKAGE, codeset);
+       }
+    }
+#endif
+
     for (i = 0; i < n; ++i) {
        const char* id;
        const char* name;