0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ひらがな / カタカナ / ローマ字(ヘボン・訓令・日本式)相互変換ツールを作った

0
Posted at

作ったもの

Kana Converterhttps://sen.ltd/portfolio/kana-converter/

スクリーンショット

  • ひらがな ↔ カタカナ
  • ひらがな/カタカナ ↔ ローマ字(ヘボン / 訓令 / 日本式)
  • 半角カナ ↔ 全角カナ
  • リアルタイム変換
  • スワップボタン

vanilla JS、ゼロ依存、ビルド不要node --test で 73 ケース。

ひらがな ↔ カタカナは Unicode 単位

if (code >= 0x3041 && code <= 0x3096) return String.fromCharCode(code + 0x60);

あ (0x3042) + 0x60 = ア (0x30A2)。Unicode コンソーシアムが意図的に整列させている。

3 つの公式ローマ字

かな ヘボン 訓令 日本式
shi si si
chi ti ti
tsu tu tu
ji zi di
zu zu du

ヘボン式は駅名標示などで広く使われる。訓令式は日本の小学校で教える。日本式は じ/ぢ や ず/づ を区別する最も厳密なシステム(歴史的な仮名遣いに対応)。

半角カナの濁点問題

半角カナでは濁点・半濁点が別文字 は全角 1 文字だが半角では カ + ゙ の 2 文字。文字列長が倍になる場合がある。

'': 'ガ', '': 'パ', '': 'ヴ'

ん + 母音の表記

ヘボン式では an'nai のようにアポストロフィを挟んで曖昧性を回避する(annai だと読めない):

result = result.replace(/n([あいうえおやゆよ])/g, "n'$1");

ローマ字 → かなは貪欲法

shas + ha ではなく 1 つのダイグラフとしてマッチさせるため、長いキーから順にチェックする。

シリーズ

100+ 公開ポートフォリオ シリーズの #84 です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?