Modul:Genitiv: Forskjell mellom sideversjoner
Hopp til navigering
Hopp til søk
(bugs) |
(bugfix +comments) |
||
Linje 2: | Linje 2: | ||
function p.genitiv(frame) |
function p.genitiv(frame) |
||
-- get the argument |
|||
local ord = frame.args[1] |
local ord = frame.args[1] |
||
if ord == nil then |
if ord == nil then |
||
ord = frame:getParent().args[1] |
ord = frame:getParent().args[1] |
||
end |
end |
||
-- check if an argument is found |
|||
if ord == nil then |
if ord == nil then |
||
return "<strong class='error'>Malen «genitiv» må ha ett argument</strong>" |
return "<strong class='error'>Malen «genitiv» må ha ett argument</strong>" |
||
end |
end |
||
-- try to rewrite, but note that this could fail |
|||
local status, str = pcall(function() return p._genitiv(ord) end) |
local status, str = pcall(function() return p._genitiv(ord) end) |
||
-- rewrite is done, should happen in most cases |
|||
if status == true then |
if status == true then |
||
return str |
return str |
||
end |
end |
||
-- rewrite is not done, this is a fallback but is probably an error |
|||
return ord |
return ord |
||
end |
end |
||
function p._genitiv(ord) |
function p._genitiv(ord) |
||
-- fallback for multiword, use determinative for genitive |
|||
⚫ | |||
if mw.ustring.find(ord, '%A$') -- trailing non-letter |
|||
or mw.ustring.find(ord, '%s%l+$') -- can be name, but can't be sure |
|||
then |
|||
⚫ | |||
return ord .. " sin" -- can be an additional trailing space on 'ord' |
|||
end |
end |
||
-- single word, prepare to rewrite special cases |
|||
⚫ | |||
local sb = mw.ustring.toNFC(mw.ustring.lower(mw.ustring.sub(ord, -1))) |
|||
if mw.ustring.find(sv, sb, nil, true) then |
if mw.ustring.find(sv, sb, nil, true) then |
||
-- use modifier letter apostrophe as genitive marker |
|||
⚫ | |||
else |
else |
||
-- just add the 's' genitive marker |
|||
return ord .. "s" |
return ord .. "s" |
||
end |
end |
Sideversjonen fra 8. okt. 2016 kl. 12:30
Formål
Denne modulen returnerer et ord i riktig genitivsform, avhengig av hvilken bokstav ordet slutter på. Se Mal:Genitiv for nærmere dokumentasjon.
Funksjoner
genitiv
: Brukes i {{genitiv}}_genitiv
: For bruk i andre moduler.
Brukes av
local p = {} function p.genitiv(frame) -- get the argument local ord = frame.args[1] if ord == nil then ord = frame:getParent().args[1] end -- check if an argument is found if ord == nil then return "<strong class='error'>Malen «genitiv» må ha ett argument</strong>" end -- try to rewrite, but note that this could fail local status, str = pcall(function() return p._genitiv(ord) end) -- rewrite is done, should happen in most cases if status == true then return str end -- rewrite is not done, this is a fallback but is probably an error return ord end function p._genitiv(ord) -- fallback for multiword, use determinative for genitive if mw.ustring.find(ord, '%A$') -- trailing non-letter or mw.ustring.find(ord, '%s%l+$') -- can be name, but can't be sure then return ord .. " sin" -- can be an additional trailing space on 'ord' end -- single word, prepare to rewrite special cases local sv = "sxzşŝșšśßžżź" -- a few letters that needs special treatment local sb = mw.ustring.toNFC(mw.ustring.lower(mw.ustring.sub(ord, -1))) if mw.ustring.find(sv, sb, nil, true) then -- use modifier letter apostrophe as genitive marker return ord .. "ʼ" else -- just add the 's' genitive marker return ord .. "s" end end return p