-- Error codes:
-- 1 internal
-- 2 unknown params (NOT yet)
-- 3 invalid lk (NOT yet)
-- 4 unknown lk
-- 5 base form empty
-- 6 unknown word class or unknown type in "3="" or "ordform="
-- 7 form not allowed for given langunage (NOT yet)
-- 8 both"3=" and "ordform=" fed in
local lang = require("Modul:lang")
local h3 = require("Modul:h3")
local export = {}
local function joinAndRemoveTrippleConsonant(part_1, part_2)
local joined
if part_1:sub(-2) ~= part_2:sub(1,1):rep(2) then
joined = part_1 .. part_2
else
joined = part_1:sub(1,-2) .. part_2 -- i.e. till + laga = tillaga (not tilllaga)
end
return joined
end
function export.getWikitext(frame)
local error_code = 0
local parent = frame:getParent()
local title = mw.title.getCurrentTitle()
local is_test = title.rootText == "avledning" and title.nsText == "Modul"
local lang_code = parent.args or ""
local original_word = parent.args or ""
local class_or_form = parent.args or parent.args or "" -- word class or word form
local particle = parent.args or ""
if (parent.args and parent.args) then -- "ordform=" is deprecated
error_code = 8
end
local default_descri = "avledning till"
local word_classes = {=true,=true,=true} -- "adj" much used, "verb" and "subst" very rarely
local first_parts = {
perfpart = {"perfektparticip av"},
prespart = {"presensparticip av"},
aktpart = {"aktivparticip av","P","eo","io"},
passpart = {"passivparticip av","P","eo","io"},
prespartakt = {"presensparticip aktiv av"}, -- slaviska + fi
prespartpass = {"presensparticip passiv av"}, -- slaviska + fi
pretpartakt = {"preteritumparticip aktiv av"}, -- slaviska
pretpartpass = {"preteritumparticip passiv av"}, -- slaviska
presger = {"presensgerundium av"}, -- slaviska
pretger = {"preteritumgerundium av"}, -- slaviska
perfpartakt = {"perfektparticip aktiv av","P","fi"},
perfpartpass = {"perfektparticip passiv av","P","fi"},
agentpart = {"agentparticip av","P","fi"},
agentpart1ps = {"agentparticip (1:a person singular) av","P","fi"},
agentpart2ps = {"agentparticip (2:a person singular) av","P","fi"},
agentpart1pp = {"agentparticip (1:a person plural) av","P","fi"},
agentpart2pp = {"agentparticip (2:a person plural) av","P","fi"},
agentpart3p = {"agentparticip (3:je person) av","P","fi"},
nekpart = {"nekande particip av","P","fi"}
}
local language = lang.getLanguageUCFirst(lang_code)
if (error_code==0) and (not lang.hasLanguage(lang_code)) then
error_code = 4
end
local first_part_tab = {}
local word_form = ''
local first_part = default_descri -- will get overidden if we get a word form
local second_part = ''
local third_part = ''
local p_or_n = ''
local got_word_class = false
local got_word_form = false
if (word_classes) then -- got second part (first remains default)
got_word_class = true
second_part = h3.getLongDetSing(class_or_form) -- else keep it empty
end--if
first_part_tab = first_parts -- change first part (later skip second part word class)
if type(first_part_tab)=='table' then
if type(first_part_tab)~='string' then
error_code = 1
else
got_word_form = true
first_part = first_part_tab
p_or_n = first_part_tab
end--if
end--if
if (error_code==0) and (class_or_form~='') and (not got_word_class) and (not got_word_form) then
error_code = 6 -- unknown word class or unknown type of form
end--if
if particle ~= "" and lang_code == "sv" then
local original_word_1 = mw.ustring.format("%s %s", original_word, particle)
local original_word_2 = joinAndRemoveTrippleConsonant(particle, original_word)
local entry_name_1 = original_word_1
local entry_name_2 = original_word_2
local third_part_1 = mw.ustring.format("]", entry_name_1, language, original_word_1)
local third_part_2 = mw.ustring.format("]", entry_name_2, language, original_word_2)
third_part = mw.ustring.format("%s ''och'' %s", third_part_1, third_part_2)
else
local entry_name = lang.getEntryName(lang_code, original_word)
third_part = mw.ustring.format("]", entry_name, language, original_word)
end
local full_text
if got_word_class then
full_text = mw.ustring.format(" ''%s %s'' %s", first_part, second_part, third_part)
else
full_text = mw.ustring.format(" ''%s'' %s", first_part, third_part)
end
if (original_word=='') and (error_code==0) then
error_code = 5
end
if (error_code~=0) and (error_code~=4) then
full_text = ''
end--if
if title:inNamespace(0) or is_test then
if (error_code~=0) then
full_text = full_text .. "]" .. "]"
end
end
return full_text
end
return export