Dokumentation för denna modul finns på /dok (redigera), /test
Den här modulen används för att generera innehåll till {{tagg}}
.
Vissa taggar specialbehandlas på ett mer avancerat sätt och de återfinns i modulens kod under kommentaren "-- Specialbehandla vissa taggars visningstext".
local import_sort = require("Modul:sort")
local import_lang = require("Modul:lang")
local import_param = require("Modul:param")
local taggdata = mw.loadData("Modul:tagg/data")
local export = {}
local name_short = "tagg"
local name_long = '"Mall:' .. name_short .. '"'
local function ucFirst(str)
return mw.ustring.gsub(str, "^%l", mw.ustring.upper)
end
local function discardHoles (big_table, name_prefix)
local indx = 1
local temp_value = 0
local deholed_table = {}
while true do
if (indx==8) then
break
end
if name_prefix then
if (indx==1) then
temp_value = big_table
else
temp_value = big_table
end
else
temp_value = big_table
end
temp_value = mw.text.trim (temp_value or "") -- trim only needed for anonymous
if (temp_value~="") then
deholed_table = temp_value
end
indx = indx + 1
end
return deholed_table
end
local function expandTwo (control_string, insert_m_string, insert_v_string)
local temp_string = ''
local expanded_string = ''
local x_length = 0
local x_index = 0
local chark = 0
local charl = 0
x_length = string.len (control_string)
while true do
if (x_index==x_length) then
break
end--if
chark = string.byte (control_string,(x_index+1),(x_index+1))
x_index = x_index + 1
charl = 0
if (x_index<x_length) then
charl = string.byte (control_string,(x_index+1),(x_index+1))
end--if
if ((chark==64) and (charl==77)) then -- @M cannot be empty
temp_string = insert_m_string
x_index = x_index + 1
else
if ((chark==64) and (charl==86)) then -- @V can be empty
temp_string = insert_v_string
x_index = x_index + 1
else
temp_string = string.char (chark)
end--if
end--if
expanded_string = expanded_string .. temp_string
end--while
return expanded_string
end--function expandTwo
function export.getWikitext(frame)
local legal_params = {}
local many_complaints = {}
local texter = {} -- visas inom ''(parenteser)''
local kategorier = {}
local list_bad_params = ''
local violating_string = ''
local problem_1_main = ''
local problem_2_desc = ''
local problem_3_hint = ''
local p_2_desc_expanded = ''
local error_visible = ''
local error_cat = ''
local pagename = ''
local result = ''
local error_code = 0
local boo_no_cat_true = false
local boo_no_cat_false = false
local args = frame:getParent().args
legal_params = {=7,"kat","kat2","kat3","kat4","kat5","kat6","kat7","språk","text","nocat","pagenameoverridetestonly"}
list_bad_params = import_param.go (args,legal_params)
pagename = args or mw.title.getCurrentTitle().text
boo_no_cat_true = (args=="true")
boo_no_cat_false = (args=="false")
local text = args
local lang_code = args or "sv"
many_complaints = {'Ogiltiga parametrar','@M använder inte @V',''}
many_complaints = {'Uppenbarligen ogiltig språkkod','Kod @V skickades in i @M','Använd enbart språkkoder enligt ].'}
many_complaints = {'Okänd språkkod','Kod @V skickades in i @M','Använd enbart språkkoder enligt ].'}
while true do
if list_bad_params ~= '' then
error_code = 1
violating_string = list_bad_params
break
end
if import_lang.isObviouslyInvalid(lang_code) then
error_code = 2
violating_string = '"' .. lang_code .. '"'
break
end
if not import_lang.hasLanguage(lang_code) then
error_code = 3
violating_string = '"' .. lang_code .. '"'
end
break
end
if (error_code~=0) then
problem_1_main = many_complaints
problem_2_desc = many_complaints -- @M cannot be empty, @V can be empty
problem_3_hint = many_complaints -- optional, can be empty
p_2_desc_expanded = expandTwo (problem_2_desc, name_long, violating_string)
error_cat = ']]'
error_visible = '<br><span class="error"><b>' .. problem_1_main .. ' -- ' .. p_2_desc_expanded .. '.</b></span></br>'
if (problem_3_hint~='') then
error_visible = error_visible .. problem_3_hint
end--if
end--if
local language = import_lang.getLanguageUCFirst(lang_code)
local sort_key = import_sort.getSortKey(lang_code, pagename)
function katString(kat)
return "]"
end
-- Parse the labels
for i, tagg in ipairs(discardHoles(args,nil)) do
local data = taggdata.taggar or {}
for _, kategori in ipairs(data.kat or {tagg}) do
kategorier = katString(kategori)
end
local visa = data.visa or tagg
if visa ~= "" then
-- Specialbehandla vissa taggars visningstext (för -fr- se nedan, ska ej vara inkluderad här)
local reflexiva_pronomen = {
= {"seg", "%s seg"},
= {"se", "%s se"},
= {"sig", "%s sig"},
= {"sig", "%s sig"},
= {"oneself", "%s oneself"},
= {"sik", "%s sik"},
= {"se", "%s se"},
= {"sig", "%s sig"},
= {"се", "%s се"},
= {"seg", "%s seg"},
= {"się", "%s się"},
= {"sig", "%s sig"},
= {"se", "%s se"},
= {"sich", "sich %s"},
= {"sig", "%s sig"},
}
if tagg == "reflexivt" and reflexiva_pronomen then
if not string.find(pagename, "%f" .. reflexiva_pronomen .. "%f") then
visa = visa .. ": '''" .. string.format(reflexiva_pronomen, pagename) .. "'''"
end
end
if tagg == "reflexivt" and lang_code == "fr" then
if not string.find(pagename, "%fs\'") and -- Sidnamn innehåller aldrig ’ (sned apostrof), endast ' (enkel apostrof)
not string.find(pagename, "%fse%f") then
if string.find("h", mw.ustring.sub(pagename, 1, 1)) then
elseif string.find("aeiouéèàùâêîôûëïüÿ", mw.ustring.sub(pagename, 1, 1)) then
visa = visa .. ": '''s’" .. pagename .. "'''"
else
visa = visa .. ": '''se " .. pagename .. "'''"
end
end
end
texter = visa
end
end
if text then
texter = text
end
-- Parse kat-parameters
for _, kategori in ipairs(discardHoles(args,"kat")) do
kategorier = katString(kategori)
end
result = ''
if (not boo_no_cat_true) then
if (error_code == 0) then
result = table.concat(kategorier, "")
else
result = error_cat
end
end
if #texter > 0 then
result = result .. " ''(" .. table.concat(texter, ", ") .. ")'' "
end
if (error_code ~= 0) and ((frame:preprocess ("{{REVISIONID}}") == '') or boo_no_cat_true or boo_no_cat_false) then
mw.addWarning (error_visible)
result = result .. error_visible
end
return result
end
return export