Skip to content

Instantly share code, notes, and snippets.

@kawarimidoll
Created September 11, 2022 05:13
Show Gist options
  • 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