Full-width to Half-width Katakana Conversion in Javascript

When dealing with enterprise customers in Japan, typically they still main legacy systems that have specific character entry requirements. One of such character entry requirement is entry of half-width katakana. Katakana is the Japanese equivalent of the alphabet and many legacy systems only support the half-width version of katakana. However, most modern mobile devices only allow entry of the full-width version of katakana (i.e. iPhone/iPad). Since the byte characters and lengths are different for full-width and half-width versions of katakana, most Japanese web applications resolve this issue by auto-converting full-width katakana characters into half-width katakana characters.

To show how this issue is resolved in action, I’ve prepared a simple Javascript sample to handle the conversion. In addition, since there are many definitions of what is half-width katakana and full-width katakana. I’ve prepared a list of what I think defines half-width/full-width katakana.

Half-width Katakana:

ガギグゲゴザジズゼゾダヂヅデドバビブベボヴパピプペポァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン

Full-width Katakana

ガギグゲゴザジズゼゾダヂヅデドバビブベボヴパピプペポァィゥェォャュョッーヮアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヰヲヱン

Note: You might notice that full-width katakana is wider than half-width katakana. Half-width katakana was originally meant to take a wide as an english alphabet character while full-width was meant to be as wide as traditional kanji (Japanese) characters.

Code Implementation

The simplest way to implement this is to just implement a straight replacement of characters using search and replace. I’ve provided a sample search and replace code in a JSFiddle for those looking to see an implementation.

http://jsfiddle.net/mkgo69gk/3/

コメントを残す

以下に詳細を記入するか、アイコンをクリックしてログインしてください。

WordPress.com ロゴ

WordPress.com アカウントを使ってコメントしています。 ログアウト /  変更 )

Google フォト

Google アカウントを使ってコメントしています。 ログアウト /  変更 )

Twitter 画像

Twitter アカウントを使ってコメントしています。 ログアウト /  変更 )

Facebook の写真

Facebook アカウントを使ってコメントしています。 ログアウト /  変更 )

%s と連携中

%d人のブロガーが「いいね」をつけました。