Difference between revisions of "Module:Distinguish"

From blackwiki
Jump to navigation Jump to search
test>Shirayuki
(Marked this version for translation)
(Blackwikiadmin changed the content model of the page Module:Distinguish from "wikitext" to "Scribunto")
Tag: content model change
 
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
<noinclude>
+
local mHatnote = require('Module:Hatnote')
<languages/>
+
local mHatlist = require('Module:Hatnote list')
</noinclude>{{#switch:<translate></translate>
+
local mArguments --initialize lazily
| =
+
local mTableTools --initialize lazily
{{Hatnote|1=<translate><!--T:1--> Not to be confused with</translate> [[:{{{1}}}]]{{
+
local libraryUtil = require('libraryUtil')
    #if: {{{3|}}}{{{4|}}}
+
local checkType = libraryUtil.checkType
    |{{int|comma-separator}}[[:{{{2}}}]]{{int|comma-separator}} {{
+
local p = {}
      #if: {{{4|}}}
 
      | [[:{{{3}}}]]{{int|comma-separator}}<translate><!--T:2--> &nbsp;or</translate>{{int|word-separator}}[[:{{{4}}}]]
 
      |<translate><!--T:3--> &nbsp;or</translate>{{int|word-separator}}[[:{{{3}}}]]
 
    }}
 
    | {{
 
      #if: {{{2|}}}
 
      |<translate><!--T:4--> &nbsp;or</translate>{{int|word-separator}}[[:{{{2}}}]]
 
    }}
 
  }}.}}
 
| #default=
 
  {{#invoke:Template translation|renderTranslatedTemplate|template=Template:Distinguish|noshift=1}}
 
}}<noinclude><!-- splitting these lines causes {{Documentation}} template to terminate green shading when Distinguish is used in /doc pages. -->
 
{{Documentation|content=
 
  
<translate>
+
function p.distinguish(frame)
== Examples == <!--T:5-->
+
mArguments = require('Module:Arguments')
</translate>
+
mTableTools = require('Module:TableTools')
* {{tlx|Distinguish|article1}}
+
local args = mArguments.getArgs(frame)
{{Distinguish|article1}}
+
local selfref = args.selfref
* {{tlx|Distinguish|article1|article2}}
+
local text = args.text
{{Distinguish|article1|article2}}
+
args = mTableTools.compressSparseArray(args)
* {{tlx|Distinguish|article1|article2|article3}}
+
return p._distinguish(args, text, selfref)
{{Distinguish|article1|article2|article3}}
+
end
* {{tlx|Distinguish|article1|article2|article3|article4}}
 
{{Distinguish|article1|article2|article3|article4}}
 
  
}}
+
function p._distinguish(args, text, selfref)
</noinclude>
+
checkType("_distinguish", 1, args, 'table')
 +
if #args == 0 and not text then return '' end
 +
local text = string.format(
 +
'Not to be confused with %s.',
 +
text or mHatlist.orList(args, true)
 +
)
 +
hnOptions = {selfref = selfref}
 +
return mHatnote._hatnote(text, hnOptions)
 +
end
 +
 
 +
return p

Latest revision as of 14:43, 13 December 2020

Implements {{distinguish}}.


local mHatnote = require('Module:Hatnote')
local mHatlist = require('Module:Hatnote list')
local mArguments --initialize lazily
local mTableTools --initialize lazily
local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
local p = {}

function p.distinguish(frame)
	mArguments = require('Module:Arguments')
	mTableTools = require('Module:TableTools')
	local args = mArguments.getArgs(frame)
	local selfref = args.selfref
	local text = args.text
	args = mTableTools.compressSparseArray(args)
	return p._distinguish(args, text, selfref)
end

function p._distinguish(args, text, selfref)
	checkType("_distinguish", 1, args, 'table')
	if #args == 0 and not text then return '' end
	local text = string.format(
		'Not to be confused with %s.',
		text or mHatlist.orList(args, true)
	)
	hnOptions = {selfref = selfref}
	return mHatnote._hatnote(text, hnOptions)
end

return p