Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

tlug: Katakana to Romanji conversion



>>>>> "Dmytro" == Dmytro Kovalev <dk@example.com> writes:

    Dmytro> I need some tool for conversion from Japanese personal
    Dmytro> names written in katakana into a romanji. Does anybody
    Dmytro> know about such tool available? Any platform should be OK

Load the following into your friendly neighborhood Mule.  Note that it
will blow up on punctuation, kanji, hiragana, whitespace, and
everything else that isn't in that alist.  Including half-width
katakana.  So make sure there's nothing but katakana in the region,
then do M-X katakana-to-romaji.  It does fail-safe, though.  I think :^)

楽しんでくださいね。

(defconst kana-romaji-alist
      '((?ア . "a")
	(?イ . "i")
	(?ウ . "u")
	(?エ . "e")
	(?オ . "o")
	(?カ . "ka")
	(?キ . "ki")
	(?ク . "ku")
	(?ケ . "ke")
	(?コ . "ko")
	(?ガ . "ga")
	(?ギ . "gi")
	(?グ . "gu")
	(?ゲ . "ge")
	(?ゴ . "go")
	(?サ . "sa")
	(?シ . "si")
	(?ス . "su")
	(?セ . "se")
	(?ソ . "so")
	(?ザ . "za")
	(?ジ . "ji")
	(?ズ . "zu")
	(?ゼ . "ze")
	(?ゾ . "zo")
	(?タ . "ta")
	(?チ . "chi")
	(?ツ . "tsu")
	(?ッ . "xtu")
	(?テ . "te")
	(?ト . "to")
	(?ダ . "da")
	(?ヂ . "ji")
	(?ヅ . "dzu")
	(?デ . "de")
	(?ド . "do")
	(?ナ . "na")
	(?ニ . "ni")
	(?ヌ . "nu")
	(?ネ . "ne")
	(?ノ . "no")
	(?ハ . "ha")
	(?ヒ . "hi")
	(?フ . "fu")
	(?ヘ . "he")
	(?ホ . "ho")
	(?バ . "ba")
	(?ビ . "bi")
	(?ブ . "bu")
	(?ベ . "be")
	(?ボ . "bo")
	(?パ . "pa")
	(?ピ . "pi")
	(?プ . "pu")
	(?ペ . "pe")
	(?ポ . "po")
	(?マ . "ma")
	(?ミ . "mi")
	(?ム . "mu")
	(?メ . "me")
	(?モ . "mo")
	(?ヤ . "ya")
	(?ユ . "yu")
	(?ヨ . "yo")
	(?ャ . "xya")
	(?ュ . "xyu")
	(?ョ . "xyo")
	(?ラ . "ra")
	(?リ . "ri")
	(?ル . "ru")
	(?レ . "re")
	(?ロ . "ro")
	(?ワ . "wa")
	(?ン . "n")))

(defun katakana-to-romaji (start end)
  "Translate from katakana to romaji between buffer positions START and END.

When called interactively, uses the current region.  Error handling is poor."
  (interactive "r")
  (save-excursion
    (save-restriction
      (narrow-to-region start end)
      (goto-char (point-min))
      (save-excursion
	(while (< (point) (point-max))
	  (let ((romaji (cdr (assoc (following-char) kana-romaji-alist))))
	    (if (not romaji)
		(error "That ain't no steenkin' katakana!")
	      (delete-char 1)
	      (insert romaji)))))
      (save-excursion
	(while (search-forward "xtu" nil t)
	  (delete-char -3)
	  (insert (following-char))))
      (save-excursion
	(while (search-forward "ixy" nil t)
	  (forward-char -1)
	  (delete-char -2)))
      (save-excursion
	(while (search-forward "ty" nil t)
	  (delete-char -2)
          (insert "ch"))
      (save-excursion
	(while (search-forward "sy" nil t)
	  (delete-char -2)
          (insert "sh"))
      (save-excursion
	(while (search-forward "si" nil t)
	  (forward-char -1)
	  (insert ?h))))))

---------------------------------------------------------------
Next TLUG Nomikai: 14 January 1998 19:15  Tokyo station
Yaesu Chuo ticket gate.  Or go directly to Tengu TokyoEkiMae 19:30
Chuo-ku, Kyobashi 1-1-6, EchiZenYa Bld. B1/B2 03-3275-3691
Next Saturday Meeting: 14 February 1998 12:30 Tokyo Station
Yaesu Chuo ticket gate.
---------------------------------------------------------------
a word from the sponsor:
TWICS - Japan's First Public-Access Internet System
www.twics.com  info@example.com  Tel:03-3351-5977  Fax:03-3353-6096

Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links