Module:English variant notice: Difference between revisions

Content deleted Content added
this should work
per edit request at Template talk:English variant notice#Edit request 16 August 2025 - remove unnecessary text
 
(36 intermediate revisions by 10 users not shown)
Line 1:
--TODO:add some more comments so I don't forget what everything does months later
local p = {}
local categoryHandler = require( 'Module:Category handler' ).main
local mArguments
local yesno = require('Module:Yesno')
local mArguments = require('Module:Arguments')
local n = args
 
function p.main (frame)
local fulltitle = frame:getParent():getTitle()
local templatetitle = string.sub(fulltitle, 10)
local title = mw.title.getCurrentTitle()
if mw.title.equals(title, mw.title.makeTitle('Template', title.rootText)) then --if it is on the main template page, load doc
local args n = mArguments.getArgs(frame, {parentFirst = true})
return frame:expandTemplate {title = 'English variant notice/documentation', args = frame.args}
n.variant = n.variant or templatetitle --automatically use title generated from template name
if n.doc ~= 'no' then
return frame:expandTemplate {title = 'English variant notice/documentation', args = frame.argsn}
end
end
return p._main (frame, templatetitle)
end
 
function p._main (frame, templatetitle)
n = mArguments.getArgs(frame, {parentFirst = true})
mArguments = require('Module:Arguments')
n.variant = n.variant or templatetitle --automatically use title generated from template name
local args = mArguments.getArgs(frame, {parentFirst = true})
local title = mw.title.getCurrentTitle()
local n = args
n.category = ''
n.variantspelling_examples = n.variantspelling_examples or n['spelling examples']
n.bid = not not n.id --bool of n.id, for making iupac and oxford not be added to the id if it doesn't exist
--Generate the text if it isn't specified
if not argsn.text then
n = p.modify_text (n)
n = p.base_text (n, frame)
end
n = p.cat (n, 'Wikipedia articles that use '..argsn.variant)
return p.style(n, frame)..(n.category or '')
end
 
function p.cat (n, category)
category = string.format ('[[Category:%s]]', category)
n.category = n.category..(categoryHandler{category, nocat = n.nocat, page = n.page, talk = category, template = category} or '')
return n
end
 
function p.modify_text (n)
n.spelling = ''
n.extravariant = ''
Line 40 ⟶ 45:
bOxford = yesno(n.Oxford)
bIUPAC = yesno(n.IUPAC)
chemtext = "; ''aluminium'', ''sulfur'', and ''caesium''"
if bOxford then
n.spelling_examples = "''colour'', ''realize'', ''organization'', ''analyse''; note that '''-ize''' is used instead of -ise"
n = p.cat (n, 'Wikipedia articles that use Oxford spelling')
if n.bid then n.id = n.id..n.Oxford end
if bIUPAC then
n.extravariant = ' with [[Oxford spelling|Oxford]] and [[IUPAC]] spelling'
n.spelling_examples= n.spelling_examples..chemtext
n = p.IUPAC (n)
return n
end
n.extravariant = n.extravariant..' with [[Oxford spelling]]'
return n
elseif bIUPAC then
n.extravariant = ' with [[IUPAC]] spelling'
n.spelling_examples = n.spelling_examples and n.spelling_examples..chemtext or "''aluminium'', ''sulfur'', and ''caesium''"
n = p.IUPAC (n)
return n
end
n.--only if there are spelling = 'examples, whichput 'has its own spelling conventions' --if none of the special (Oxford, IUPAC) modifications are there, put this
if n.spelling_examples then n.spelling = ', which has its own spelling conventions' end
return n
end
 
function p.IUPAC (n)
n.extraguide = ' and [[Wikipedia:Naming conventions (chemistry)|chemistry naming conventions]]'
n = p.cat(n, 'Wikipedia articles that use IUPAC spelling')
n.flag = 'no'
if n.bid then n.id = n.id..'iupac' end
return n
end
 
function p.base_text (n, frame)
n.subjectspace = frame:expandTemplate{ title = require('SUBJECTSPACE_formattedModule:Pagetype' }).main()
n.spelling_examples = n.spelling_examples and string.format(' (%s)', n.spelling_examples) or ' (colour, realise, travelled)'
--for spelling examples, have default commonwealth standard text
n.spelling_examples = n.spelling_examples and string.format(' (%s)', n.spelling_examples) or ' (colour, realise, travelled)'
n.terms = n[1] or n.terms
n.terms = n.terms and string.format(', (including %s,)', n.terms) or ''
n.compare = n.compare and (n.compare..' ') or ''
n.text = string.format([=[This %s is '''written in [[%s]]%s'''%s%s, and some terms that are used in it%s may be different or absent from %sother [[List of dialects of the English language|varieties of English]]. According to the [[WPWikipedia:ENGVARManual of Style#National varieties of English|relevant style guide]]%s, this should not be changed without [[Wikipedia:Consensus#Levels of consensus|broad consensus]].__EXPECTUNUSEDTEMPLATE__]=],
n.subjectspace, n.variant, n.extravariant, n.spelling, n.spelling_examples, n.terms, n.compare, n.extraguide)
return n
end
 
function p.style (n, frame)
local size
if yesno(n.small) then size = '30px' else size = '50px' end
elseif n.size then size = n.size
else size = '50px'
end
if n.image then
if n.flag == nil or yesno(n.flag) then
Line 97 ⟶ 104:
end
if n.form == 'editnotice' then
if n.bid then n.id = n.id..'editnotice' end
n.expiry = n.expiry or 'indefinite'
--categorize editnotice if specified
if yesno(n.editnotice_cat) then
n = p.cat(n, string.format('Pages with editnotice %s editnotice', n.variant))
end
return frame:expandTemplate{title = 'editnotice', args = n}
else
local message_box = require('Module:Message box').main
if not n.image then n.image = 'none' end
n['type'] = 'style'
return message_box.main ('tmbox', n)
end
end