Module:User:Eirikr/ja-phon-dev

local export = {}

function export.main( frame ) args = frame:getParent.args

ojp = args["ojp"] if ojp ~= nil then reply = export.format_ojp(ojp) else reply = 'OJP string is empty!' end

return reply end

function export.format_ojp(ojp_string) -- Validate string -- we only allow IPA chars and numbers 1 and 2. Any other numbers should generate an error message. -- Numbers are also restricted to following *only* the vowels `e`, `i`, and `o`. if (string.match(ojp_string, '[03-9]') or string.match(ojp_string, '[0-9]{2}') or string.match(ojp_string, '[^eio][0-9]')) then -- generate error message end

-- Replace digits with '\d' numsub = string.gsub( ojp_string, "[12]", "%1" )

output = '[ ⟨' .. numsub .. '⟩ ](Old Japanese)' output = mw.ustring.gsub(output, "%[([^%[%]]+)%]%(([^%(%)]+)%)", " %1%2 ") output = mw.ustring.gsub(output, "(.)%(([^%(%)]+)%)", " %1%2 ") return output end

return export