UTF-8/ko

UTF-8은 가변 길이 문자 인코딩이며, 심볼당 1바이트에서 4바이트를 사용합니다. 따라서 첫번째 UTF-8 바이트는 ASCII에 대한 이전 호환성을 완전히 갖춘 문자 세트를 제공하는 ASCII 인코딩 용도로 사용합니다. UTF-8은 ASCII와 라틴 문자를 데이터의 크기를 크게 변화하지 않고도 상호 표현이 가능함을 의미하는데, 첫 번째 바이트만 활용하기 때문입니다. 상위 바이트 범위를 할당 받아 만족하지 않는 일본어권 사용자 같은 동방 문자 사용자들에게는 최대 50%의 데이터 중복을 취하게 되었습니다.

문자 인코딩이란 무엇인가요?
컴퓨터는 자체적으로 텍스트를 이해하지 못합니다. 대신 모든 문자를 숫자로 표현합니다. 옛부터 각 숫자 모음은 알파벳과 문자를 표현하는데 사용했습니다(코딩 시스템, 인코딩, 문자세트로 알려져왔습니다)만 컴퓨터 하드웨어의 제한으로, 크기의 제한을 받았습니다.

문자 인코딩 역사
가장 일반적(또는 최소한 광범위하게 수용해온) 문자세트는 ASCII(정보 교환용 미 표준 코드)였습니다. 지금껏 소프트웨어 표준에 있어 가장 성공적으로 이끌어온 ASCII야 말로 광범위하게 사용되었ㅅ브니다. 최신 ASCII는 1986년도에 미 국립 표준 협회에서 표준으로 제정(ANSI X3.4, RFC 20, ISO/IEC 646:1991, ECMA-6) 했습니다.

ASCII는 7비트로 엄격하게 제한되었으며, 표현 가능한 7개의 이진수로 비트 패턴을 사용함을 의미하는데, 10진수로는 0부터 127까지의 범위를 제공합니다. 여기에는 32개의 보이지 않는 제어 문자가 있는데, 0부터 31까지의 범위에 있으며, 마지막 제어 문자는 DEL또는 delete이며, 이 제어문자는 127번에 할당되어 있습니다. 32번 부터 126번 까지는 공백 문자, 문장 부호, 라틴 문자, 숫자와 같은 눈에 보이는 문자로 구성되어 있습니다.

ASCII의 8번째 비트는 본디 오류 검출을 위한 패리티 비트로 활용했습니다. 용도를 고려하지 않으면 0으로 그대로 내버려두었습니다. ASCII에서 각 문자를 단일 바이트로 표현했음을 의미합니다.

ASCII를 최근의 영문 의사소통을 하는데는 충분했었지만, 강세부호가 들어간 문자가 있는 다른 유럽어권의 문자에 대해서는 그렇지 않았습니다. 이런 필요성 때문에 ISO 8859 표준을 개발했습니다. ASCII와의 이전 호환성을 유지했지만 8번째 비트를 빈 채로 내버려두는 대신에 각 인코딩 주소에 다른 127개의 문자를 넣도록 했습니다. ISO 8859의 한계는 곧 다가왔고, 현재 ISO 8859 표준의 15가지 변형 표준이 있습니다. 이러한 문자 세트의 ASCII 호환 바이트 범위밖에서는 각 바이트로 표현하는 문자간의 충돌이 종종 일어났습니다. 문자 인코딩간 상호 처리를 좀 더 복잡하게 처리하기 위해 일부 마이크로소프트 윈도우 버전에서는 서유럽어권에 대해 Windows-1252 표준을 사용했습니다. 이 표준은 ISO-8859-1의 상위 집합이지만 여러모로 다른 점이 있었습니다. 그러나 이러한 세트는 ASCII 호환성을 유지했습니다.

일본어와 한국어 같은 언어를 대상으로 사용하는 EUC(확장 유닉스 코딩)와 같은 비 라틴어 계열 문자를 대상한 완전히 다른 단일 바이트 인코딩의 개발 필요성은, 이미 다른 운영체제에서 동일한 언어에 대해 Shift-JIS, ISO-2022-JP와 같은 다른 문자셋을 이미 사용하고 있는 상황에서 더욱 혼동감을 가져왔습니다. 키릴 자모를 보려는 사용자는 러시아와 불가리아에서 사용하는 KOI8-R, 우크라이나에서 사용하는 KOI8-U, 온전치 못한 ISO 8859-5, 보통 사용하던 Windows-1251 세트 중 하나를 선택해야 했습니다. 이들 대부분의 모든 문자세트는 ASCII와의 호환성을 깨뜨렸습니다(비록 KOI8 인코딩은 라틴 문자 숫서대로 키릴 문자를 배치했지만, 이 경우 8번째 비트는 제거되었으며, 텍스트는 대소문자가 뒤집힌 음역 상태로 ASCII 터미널에서 해석 가능했습니다).

이러한 판단 추세가 혼동을 가져왔으며, 다중 언어 의사 소통에 있어 거의 완전하게 불가능했고, 특히 다른 문자에 대해서도 불가능했습니다. 이제 유니코드로 들어가보도록 하겠습니다.

What is Unicode?
Unicode throws away the traditional single-byte limit of character sets. It uses 17 "planes" of 65,536 code points to describe a maximum of 1,114,112 characters. As the first plane, aka. "Basic Multilingual Plane" or BMP, contains almost everything you will ever use, many have made the wrong assumption that Unicode was a 16-bit character set.

Unicode has been mapped in many different ways, but the two most common are UTF (Unicode Transformation Format) and UCS (Universal Character Set). A number after UTF indicates the number of bits in one unit, while the number after UCS indicates the number of bytes. UTF-8 has become the most widespread means for the interchange of Unicode text as a result of its eight-bit clean nature, and it is the subject of this document.

What UTF-8 Can Do for You
UTF-8 allows you to work in a standards-compliant and internationally accepted multilingual environment, with a comparatively low data redundancy. UTF-8 is the preferred way for transmitting non-ASCII characters over the Internet, through Email, IRC or almost any other medium. Despite this, many people regard UTF-8 in online communication as abusive. It is always best to be aware of the attitude towards UTF-8 in a specific channel, mailing list or Usenet group before using non-ASCII UTF-8.

Finding or Creating UTF-8 Locales
Now that you understand the principles behind Unicode, you're ready to start using UTF-8 with your system.

The preliminary requirement for UTF-8 is to have a version of glibc installed that has national language support. The recommend means to do this is the file. It is beyond the scope of this document to explain the usage of this file though. It is explained in the Gentoo Localization Guide.

Next, we'll need to decide whether a UTF-8 locale is already available for our language, or whether we need to create one.

From the output of this command line, we need to take the result with a suffix similar to. If there is no result with a suffix similar to, we need to create a UTF-8 compatible locale.

Replace "en_GB" with your desired locale setting:

Another way to include a UTF-8 locale is to add it to the file and generate necessary locales with   command.

Line in /etc/locale.gen

Setting the Locale
There is one environment variable that needs to be set in order to use our new UTF-8 locales:  (or optionally , if you want to change the system language as well). There are also many different ways to set it; some people prefer to only have a UTF-8 environment for a specific user, in which case they set them in their (if you use   ),  or  (if you use  ). More details and best practices can be found in our Localization Guide.

Others prefer to set the locale globally. One specific circumstance where the author particularly recommends doing this is when is in use, because this init script starts the display manager and desktop before any of the aforementioned shell startup files are sourced, and so before any of the variables are in the environment.

Setting the locale globally should be done using. The file should look something like the following:

Demonstration /etc/env.d/02locale

Next, the environment must be updated with the change.

Now, run  with no arguments to see if we have the correct variables in our environment:

That's everything. You are now using UTF-8 locales, and the next hurdle is the configuration of the applications you use from day to day.

Application Support
When Unicode first started gaining momentum in the software world, multibyte character sets were not well suited to languages like C, in which many of the day-to-day programs people use are written. Even today, some programs are not able to handle UTF-8 properly. Fortunately, most are!

Filenames, NTFS, and FAT
There are several NLS options in the Linux kernel configuration menu, but it is important to not become confused! For the most part, the only thing you need to do is to build UTF-8 NLS support into your kernel, and change the default NLS option to utf8.

If you plan on mounting NTFS partitions, you may need to specify an  option with mount. If you plan on mounting FAT partitions, you may need to specify a  option with mount. Optionally, you can also set a default codepage for FAT in the kernel configuration. Note that the  option with mount will override the kernel settings.

You should avoid setting  to UTF-8, as it is not recommended. Instead, you may want to pass the option utf8=true when mounting your FAT partitions. For further information, see  and the kernel documentation at.

For changing the encoding of filenames, can be used.

The format of the  command is as follows:

Substitute iso-8859-1 with the charset you are converting from:

For changing the contents of files, use the  utility, bundled with. Substitute iso-8859-1 with the charset you are converting from, and check that the output is sane:

To convert a file, you must create another file:

can also be used for this purpose.

The System Console
To enable UTF-8 on the console, you should edit and set , and also read the comments in that file -- it is important to have a font that has a good range of characters if you plan on making the most of Unicode. For this to work, make sure you have properly created a Unicode locale.

The  variable, set in, should have a Unicode keymap specified.

Example /etc/conf.d/keymaps snippet

Ncurses and Slang
It is wise to add  to your global USE flags in, and then to remerge  and  if appropriate. Portage will do this automatically when you update your system:

We also need to rebuild packages that link to these, now the USE changes have been applied. The tool we use is part of the  package.

KDE, GNOME and Xfce
All of the major desktop environments have full Unicode support, and will require no further setup than what has already been covered in this guide. This is because the underlying graphical toolkits (Qt or GTK+2) are UTF-8 aware. Subsequently, all applications running on top of these toolkits should be UTF-8-aware out of the box.

The exceptions to this rule come in Xlib and GTK+1. GTK+1 requires a iso-10646-1 FontSpec in the ~/.gtkrc, for example. Also, applications using Xlib or Xaw will need to be given a similar FontSpec, otherwise they will not work.

Example ~/.gtkrc (for GTK+1) that defines a Unicode compatible font

If an application has support for both a Qt and GTK+2 GUI, the GTK+2 GUI will generally give better results with Unicode.

X11 and Fonts
TrueType fonts have support for Unicode, and most of the fonts that ship with Xorg have impressive character support, although, obviously, not every single glyph available in Unicode has been created for that font. To build fonts (including the Bitstream Vera set) with support for East Asian letters with X, make sure you have the  USE flag set. Many other applications utilise this flag, so it may be worthwhile to add it as a permanent USE flag.

Also, several font packages in Portage are Unicode aware.

Window Managers and Terminal Emulators
Window managers not built on GTK+ or Qt generally have very good Unicode support, as they often use the Xft library for handling fonts. If your window manager does not use Xft for fonts, you can still use the FontSpec mentioned in the previous section as a Unicode font.

Terminal emulators that use Xft and support Unicode are harder to come by. Aside from Konsole and gnome-terminal, the best options in Portage are, , , , or plain when built with the   USE flag and invoked as. supports UTF-8 too, when invoked as  or the following is put into the :

~/.screenrc for UTF-8

Vim, Emacs, Xemacs and Nano
Vim provides full UTF-8 support, and also has builtin detection of UTF-8 files. For further information in Vim, use.

GNU Emacs since version 23 and XEmacs version 21.5 have full UTF-8 support. GNU Emacs 24 also supports editing bidirectional text.

Nano has provided full UTF-8 support since version 1.3.6.

Shells
Currently,  provides full Unicode support through the GNU readline library. Z Shell offers Unicode support with the   USE flag.

The C shell,  and   do not provide UTF-8 support at all.

Irssi
Irssi has complete UTF-8 support, although it does require a user to set an option.

For channels where non-ASCII characters are often exchanged in non-UTF-8 charsets, the  command may be used to convert the characters. Type  for more information.

Mutt
The Mutt mail user agent has very good Unicode support. To use UTF-8 with Mutt, you don't need to put anything in your configuration files. Mutt will work under unicode enviroment without modification if all your configuration files (signature included) are UTF-8 encoded.

Further information is available from the Mutt Wiki.

Man
Man pages are an integral part of any Linux machine. To ensure that any unicode in your man pages render correctly, edit and replace a line as shown below.

man.conf changes for Unicode support

elinks and links
These are commonly used text-based browsers, and we shall see how we can enable UTF-8 support on them. On  and , there are two ways to go about this, one using the Setup option from within the browser or editing the config file. To set the option through the browser, open a site with  or   and then  +  to enter the Setup Menu then select Terminal options, or press. Scroll down and select the last option  by pressing. Then Save and exit the menu. On  you may have to do a repeat  +  and then press  to save. The config file option, is shown below.

Enabling UTF-8 for elinks/links

Samba
Samba is a software suite which implements the SMB (Server Message Block) protocol for UNIX systems such as Macs, Linux and FreeBSD. The protocol is also sometimes referred to as the Common Internet File System (CIFS). Samba also includes the NetBIOS system - used for file sharing over windows networks.

add the following under the [global] section:

Testing it all out
There are numerous UTF-8 test websites around. ,, , and all Mozilla based browsers (including Firefox) support UTF-8. Konqueror and Opera have full UTF-8 support too.

When using one of the text-only web browsers, make absolutely sure you are using a Unicode-aware terminal.

If you see certain characters displayed as boxes with letters or numbers inside, this means that your font does not have a character for the symbol or glyph that the UTF-8 wants. Instead, it displays a box with the hex code of the UTF-8 symbol.


 * A W3C UTF-8 Test Page
 * A UTF-8 test page provided by the University of Frankfurt

Input Methods
Dead keys may be used to input characters in X that are not included on your keyboard. These work by pressing your right key (or in some countries, ) and an optional key from the non-alphabetical section of the keyboard to the left of the return key at once, releasing them, and then pressing a letter. The dead key should modify it. Input can be further modified by using the key at the same time as pressing the  and modifier.

To enable dead keys in X, you need a layout that supports it. Most European layouts already have dead keys with the default variant. However, this is not true of North American layouts. Although there is a degree of inconsistency between layouts, the easiest solution seems to be to use a layout in the form "en_US" rather than "us", for example. The layout is set in like so:

/etc/X11/xorg.conf snippet

This change will come into effect when your X server is restarted. To apply the change now, use the  tool, for example,.

It is probably easiest to describe dead keys with examples. Although the results are locale dependent, the concepts should remain the same regardless of locale. The examples contain UTF-8, so to view them you need to either tell your browser to view the page as UTF-8, or have a UTF-8 locale already configured.

When I press and  at once, release them, and then press, 'ä' is produced. When I press and  at once, and then press, 'ë' is produced. When I press and  at once, and then press, 'á' is produced, and when I press  and  at once, release them, and then press , 'é' is produced.

By pressing, and  at once, releasing them, and then pressing , a Scandinavian 'å' is produced. Similarly, when I press, and  at once, release only the , and then press it again, '°' is produced. Although it looks like one, this (U+02DA) is not the same as a degree symbol (U+00B0).

can be used with alphabetical keys alone. For example, and, a Greek lower-case letter mu is produced. and produce a scharfes s or esszet, etc. As many European users would expect (because it is marked on their keyboard),  and  (or  depending on the keyboard layout) produces a Euro sign, '€'.

Resources

 * The Wikipedia entry for Unicode
 * The Wikipedia entry for UTF-8
 * Unicode.org
 * UTF-8.com
 * RFC 3629
 * RFC 2277
 * Characters vs. Bytes

System Configuration Files (in /etc)
Most system configuration files, such as, do not support UTF-8. It is recommended to stick with the ASCII character set for these files.

Acknowledgements
We would like to thank the following authors and editors for their contributions to this guide:


 * Thomas Martin
 * Alexander Simonov
 * Shyam Mani
 * nightmorph