Module:English variant notice
Appearance
![]() | This Lua module is used on 70,000+ pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
This module is for generating various english variant notice templates.
Automatically generates "variant" from title template that invokes it (e.g invoking from "Template:American English" gives "American English" as variant).
All templates using this support a |Oxford=
parameter for oxford spelling and |IUPAC=
automatically.
Usage
- small, form and including – unnecessary to use in templates as grabbed when passed in from talk pages
- id – the HTML id used in editnotices; "editnotice" is automatically appended
- image – name of file to be used as an icon, without the File: prefix.
- variant – defaults to the template name; the variant of English, which should be a Wikipedia article.
- spelling examples –gives spelling examples in parentheses
- compare –comparison variants of english
- text – custom text, set only if required to be different from the default
- doc if set to no, will not load the automatic documentation at Template:English variant notice/documentation
- editnotice_cat if set to yes, categorizes in edit notice category
- nocat disables documentation if set to true
- size set the size of the image (example:
|size=60px
)
Example
As of March 2018, Template:Hiberno-English uses the following parameters:
{{#invoke:English variant notice|main | id = hie | image = Four Provinces Flag.svg{{!}}border | spelling_examples = ''colour'', ''realise'', ''travelled'' | compare = [[British English|English]], [[Scottish English|Scottish]] and }}
which produces: Lua error at line 19: attempt to index local 'n' (a nil value).
See also
- The {{Use X English}} templates
--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')
function p.main (frame)
mArguments = require('Module:Arguments')
local args = mArguments.getArgs(frame, {parentFirst = true})
title = mw.title.getCurrentTitle()
if mw.title.equals(title, mw.title.makeTitle('Template', title.rootText)) then
return frame:expandTemplate {title = 'English variant notice/documentation', args = args}
end
return p._main (frame, args)
end
function p._main (frame)
local n = args
n.category = ''
--Generate the text if it isn't specified
if not args.text then
n = p.modify_text (n)
n = p.base_text (n, frame)
end
n = p.cat (n, 'Wikipedia articles that use '..args.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 = ''
n.extraguide = ''
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 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.spelling = ', which has its own spelling conventions' --if none of the special (Oxford, IUPAC) modifications are there, put this
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'
return n
end
function p.base_text (n, frame)
n.subjectspace = frame:expandTemplate{ title = 'SUBJECTSPACE_formatted' }
--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 [[WP:ENGVAR|relevant style guide]]%s, this should not be changed without broad consensus.]=],
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
if n.image then
if n.flag == nil or yesno(n.flag) then
n.image = string.format('[[File:%s|%s]]', n.image, size)
else
--check if the globe should be "color" instead of "colour"
if yesno(n.color) then
n.image = string.format('[[File:Globe spelling color.png|%s]]', size)
else
n.image = string.format('[[File:Globe spelling colour.svg|%s]]', size)
end
end
end
if n.form == 'editnotice' then
--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')
if not n.image then n.image = 'none' end
n['type'] = 'style'
return message_box.main('tmbox', n)
end
end
return p