Skip to content

Instantly share code, notes, and snippets.

@kawarimidoll
Created September 11, 2022 05:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kawarimidoll/10531d839b9aa42304b77a89fa320f10 to your computer and use it in GitHub Desktop.
Save kawarimidoll/10531d839b9aa42304b77a89fa320f10 to your computer and use it in GitHub Desktop.
generate romaji-kana table for japanese input
-- https://support.microsoft.com/ja-jp/topic/%E3%83%AD%E3%83%BC%E3%83%9E%E5%AD%97%E5%85%A5%E5%8A%9B%E3%81%AE%E3%81%A4%E3%81%A5%E3%82%8A%E4%B8%80%E8%A6%A7%E8%A1%A8%E3%82%92%E7%A2%BA%E8%AA%8D%E3%81%97%E3%81%A6%E3%81%BF%E3%82%88%E3%81%86-bcc0ad7e-2781-cc9a-e524-7de506d8fdae
local roman_kana_table = {
-- common symbols in japanese writings
['~'] = '~', [','] = '、', ['.'] = '。', ['/'] = '・',
['-'] = 'ー', ['['] = '「', [']'] = '」',
-- other full-space symbols
-- ['!']='!', ['"']='”', ['#']='#', ['$']='$', ['%']='%',
-- ['&']='&', [''']='’', ['(']='(', [')']=')', ['*']='*',
-- ['+']='+', [',']=',', ['-']='-', ['.']='.', ['/']='/',
-- [':']=':', [';']=';', ['<']='<', ['=']='=', ['>']='>',
-- ['?']='?', ['@']='@', ['[']='[', ['\\']='\', ['¥']='¥',
-- [']']=']', ['^']='^', ['_']='_', ["'"]='’', ['{']='{',
-- ['|']='|', ['}']='}',
-- japanese characters
['a'] = 'あ', ['i'] = 'い', ['u'] = 'う', ['e'] = 'え', ['o'] = 'お',
['ka'] = 'か', ['ki'] = 'き', ['ku'] = 'く', ['ke'] = 'け', ['ko'] = 'こ',
['ga'] = 'が', ['gi'] = 'ぎ', ['gu'] = 'ぐ', ['ge'] = 'げ', ['go'] = 'ご',
['sa'] = 'さ', ['si'] = 'し', ['su'] = 'す', ['se'] = 'せ', ['so'] = 'そ',
['za'] = 'ざ', ['zi'] = 'じ', ['zu'] = 'ず', ['ze'] = 'ぜ', ['zo'] = 'ぞ',
['ta'] = 'た', ['ti'] = 'ち', ['tu'] = 'つ', ['te'] = 'て', ['to'] = 'と',
['da'] = 'だ', ['di'] = 'ぢ', ['du'] = 'づ', ['de'] = 'で', ['do'] = 'ど',
['na'] = 'な', ['ni'] = 'に', ['nu'] = 'ぬ', ['ne'] = 'ね', ['no'] = 'の',
['ha'] = 'は', ['hi'] = 'ひ', ['hu'] = 'ふ', ['he'] = 'へ', ['ho'] = 'ほ',
['ba'] = 'ば', ['bi'] = 'び', ['bu'] = 'ぶ', ['be'] = 'べ', ['bo'] = 'ぼ',
['pa'] = 'ぱ', ['pi'] = 'ぴ', ['pu'] = 'ぷ', ['pe'] = 'ぺ', ['po'] = 'ぽ',
['ma'] = 'ま', ['mi'] = 'み', ['mu'] = 'む', ['me'] = 'め', ['mo'] = 'も',
['ya'] = 'や', ['yu'] = 'ゆ', ['ye'] = 'いぇ', ['yo'] = 'よ',
['ra'] = 'ら', ['ri'] = 'り', ['ru'] = 'る', ['re'] = 'れ', ['ro'] = 'ろ',
['wa'] = 'わ', ['wi'] = 'うぃ', ['wu'] = 'う', ['we'] = 'うぇ', ['wo'] = 'を',
['nn'] = 'ん',
}
local function apply_lx_keys(base, kana)
roman_kana_table['l' .. base] = kana
roman_kana_table['x' .. base] = kana
end
apply_lx_keys('a', 'ぁ')
apply_lx_keys('i', 'ぃ')
apply_lx_keys('u', 'ぅ')
apply_lx_keys('e', 'ぇ')
apply_lx_keys('o', 'ぉ')
apply_lx_keys('tu', 'っ')
apply_lx_keys('tsu', 'っ')
apply_lx_keys('ya', 'ゃ')
apply_lx_keys('yu', 'ゅ')
apply_lx_keys('yo', 'ょ')
apply_lx_keys('wa', 'ゎ')
local function small_key_combinations(consonant, kana, type, skip)
local base = { ['ya'] = 'ゃ', ['yi'] = 'ぃ', ['yu'] = 'ゅ', ['ye'] = 'ぇ', ['yo'] = 'ょ', }
if type == 'w' then
base = { ['wa'] = 'ぁ', ['wi'] = 'ぃ', ['wu'] = 'ぅ', ['we'] = 'ぇ', ['wo'] = 'ぉ', }
elseif type == 'h' then
base = { ['ha'] = 'ゃ', ['hi'] = 'ぃ', ['hu'] = 'ゅ', ['he'] = 'ぇ', ['ho'] = 'ょ', }
elseif type == 'l' then
base = { ['a'] = 'ぁ', ['i'] = 'ぃ', ['u'] = 'ぅ', ['e'] = 'ぇ', ['o'] = 'ぉ', }
end
for k, v in pairs(base) do
if k == skip then
roman_kana_table[consonant .. k] = kana
else
roman_kana_table[consonant .. k] = kana .. v
end
end
end
small_key_combinations('k', 'き', 'y')
small_key_combinations('g', 'ぎ', 'y')
small_key_combinations('s', 'し', 'y')
small_key_combinations('z', 'じ', 'y')
small_key_combinations('t', 'ち', 'y')
small_key_combinations('c', 'ち', 'y')
small_key_combinations('d', 'ぢ', 'y')
small_key_combinations('n', 'に', 'y')
small_key_combinations('h', 'ひ', 'y')
small_key_combinations('b', 'び', 'y')
small_key_combinations('p', 'ぴ', 'y')
small_key_combinations('m', 'み', 'y')
small_key_combinations('r', 'り', 'y')
small_key_combinations('j', 'じ', 'y')
small_key_combinations('q', 'く', 'y')
small_key_combinations('f', 'ふ', 'y')
small_key_combinations('v', 'ゔ', 'y')
small_key_combinations('s', 'す', 'w')
small_key_combinations('k', 'く', 'w')
small_key_combinations('q', 'く', 'w')
small_key_combinations('g', 'ぐ', 'w')
small_key_combinations('f', 'ふ', 'w')
small_key_combinations('t', 'と', 'w')
small_key_combinations('d', 'ど', 'w')
small_key_combinations('wh', 'う', 'l', 'u')
small_key_combinations('q', 'く', 'l', 'u')
small_key_combinations('ts', 'つ', 'l', 'u')
small_key_combinations('f', 'ふ', 'l', 'u')
small_key_combinations('v', 'ゔ', 'l', 'u')
small_key_combinations('sh', 'し', 'y', 'i')
small_key_combinations('j', 'じ', 'y', 'i')
small_key_combinations('ch', 'ち', 'y', 'i')
small_key_combinations('t', 'て', 'h')
small_key_combinations('d', 'で', 'h')
local consonant_list = {
'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n',
'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z',
}
for _, k in ipairs(consonant_list) do
roman_kana_table[k .. k] = 'っ' .. k
if k ~= 'n' then
roman_kana_table['n' .. k] = 'ん' .. k
end
end
return roman_kana_table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment