local export = {}
-- This is based on the function in Module:translations/multi. local function get_args(template_content) local args = {} local i = 0
for arg in mw.text.gsplit(template_content, "¦", true) do local name, value = arg:match("^(.-)=(.-)$") if name then if value ~= "" then name = tonumber(name) or name args = value end elseif arg == "" then i = i + 1 args = nil else i = i + 1 args = arg end end
return args end
local script_data = mw.loadData "Module:scripts/data" local kana = script_data.Kana.characters .. script_data.Hira.characters local kana_pattern = "^+$" local function is_kana(str) return mw.ustring.find(str, kana_pattern) ~= nil end
local ja_link = require "Module:ja-link".link local function process_ja_r_template(template_content) local args = get_args(template_content)
-- This logic is copied from Module:ja-link. local kana = args if not kana then kana = args if not (kana and is_kana(kana)) then -- error end end
local data = { lemma = args, kana = kana, gloss = args, lit = args, pos = args, linkto = args, transliteration = args, }
local options = { caps = args, hist = args, }
return ja_link(data, options) end
function export.main(frame) local wikicode = frame:getParent().args
if not wikicode then return "" else local result = (mw.ustring.gsub(wikicode, "⦃⦃ja%-r¦(+)⦄⦄", process_ja_r_template)) return result end end
return export