Module:number list: difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
This is what ObsequiousNewt proposed, and what I agree with. |
||
Line 52: | Line 52: | ||
if cur_data["numeral"] then |
if cur_data["numeral"] then |
||
cur_display = |
cur_display = m_links.full_link(nil, cur_data["numeral"], lang, nil, nil, nil, {tr = "-"}, false) .. "<br/><span style=\"font-size: smaller;\">" .. cur_display .. "</span>" |
||
end |
end |
||
Revision as of 23:13, 5 July 2015
- The following documentation is located at Module:number list/documentation. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module generates navigation boxes for number words, such as three, third, thrice, and triple. It is used by {{number box}}
, {{cardinalbox}}
, {{ordinalbox}}
, {{adverbialbox}}
, and {{collectivebox}}
. The language-specific submodules are used by {{number box}}
.
Language-specific submodules
- aa
- acy
- af
- afb
- aii
- aii/sandbox
- ajp
- akk
- alt
- am
- ane
- ang
- ar
- art-dtk
- art-nav
- ary
- arz
- as
- ase
- av
- az
- bar
- bbl
- bcl
- be
- bg
- bn
- bo
- brh
- bug
- bxd
- ca
- cau-nkh-pro
- ccp
- ce
- ceb
- crh
- crp-slb
- cs
- csb
- cu
- cv
- cy
- da
- de
- doi
- dra-pro
- dtp
- egy
- ekg
- el
- el/documentation
- el/sandbox
- en
- enm
- eo
- es
- et
- eu
- fa
- fax
- fi
- fr
- frr
- fur
- ga
- gd
- gl
- got
- grc
- grk-pro
- gu
- ha
- haw
- he
- hi
- hi/documentation
- hil
- hrx
- hu
- huu
- hy
- id
- ig
- igl
- inc-oas
- inc-pra
- inh
- io
- is
- it
- ja
- jam
- jje
- jpx-pro
- jpx-ryu-pro
- ka
- ka/sandbox
- kca-eas
- kca-nor
- kfa
- kfr
- khb
- kk
- kl
- km
- kn
- ko
- koi
- kpv
- ks
- ky
- la
- ldn
- lo
- lt
- luq
- lv
- mai
- mch
- mhj
- mhr
- mk
- mkj
- ml
- mn
- mnc
- mni
- mns-nor
- mr
- mrw
- mt
- my
- nci
- ne
- nl
- non
- nxq
- or
- orv
- os
- pa
- pa-Arab
- phr/sandbox
- pl
- pnb
- pqm
- pt
- qya
- rgn
- rhg
- rif
- rmf
- ro
- rom
- ru
- rue
- sa
- sah
- sat
- scl
- sco
- sd
- se
- sem-pro
- sh
- shn
- si
- sia
- sjd
- sje
- sjn
- sju
- sk
- skr
- sl
- sla-pro
- sma
- smj
- smn
- sms
- sq
- sux
- sv
- sw
- syl
- szy
- ta
- tab
- tcy
- te
- tg
- th
- tk
- tl
- tlh
- tpi
- tpw
- tr
- trk-pro
- tru
- tt
- ttj
- tuw-pro
- tzm
- ug
- uk
- uma
- und
- ur
- urk
- uz
- vep
- vi
- vot
- wuh
- xnt
- yi
- ykg
- yo
- yrk
- yrl
- zle-ort
- zlw-mas
- zlw-ocs
- zlw-slv
local export = {}
local form_types = {
{key = "cardinal", display = "[[cardinal number|Cardinal]]"},
{key = "ordinal", display = "[[ordinal number|Ordinal]]"},
{key = "adverbial", display = "[[adverbial number|Adverbial]]"},
{key = "multiplier", display = "[[multiplier|Multiplier]]"},
{key = "distributive", display = "[[distributive number|Distributive]]"},
{key = "collective", display = "[[collective number|Collective]]"},
}
function export.show_box(frame)
local m_links = require("Module:links")
local params = {
[1] = {required = true},
[2] = {required = true, type = "number"},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local lang = args[1] or "und"
local cur_num = args[2] or 2
lang = require("Module:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
-- Get the data from the data module
local m_data = require("Module:number list/data/" .. lang:getCode())
local cur_data = m_data.numbers[cur_num]
-- Go over each number and make links
local forms = {}
local cur_type
for _, form_type in ipairs(form_types) do
if cur_data[form_type.key] then
table.insert(forms, " ''" .. form_type.display .. "'' : " .. m_links.full_link(cur_data[form_type.key], nil, lang, nil, nil, nil, false))
-- If this number is the current page, then store the key for later use
if lang:makeEntryName(cur_data[form_type.key]) == mw.title.getCurrentTitle().fullText then
cur_type = form_type.key
end
end
end
if not cur_type and mw.title.getCurrentTitle().nsText ~= "Template" then
error("The current page name does not match any of the numbers listed in the data module for " .. cur_num .. ". Check the data module or the spelling of the page.")
end
-- Current number in header
local cur_display = m_links.full_link(nil, cur_num, lang, sc, nil, nil, {tr = "-"}, false)
if cur_data["numeral"] then
cur_display = m_links.full_link(nil, cur_data["numeral"], lang, nil, nil, nil, {tr = "-"}, false) .. "<br/><span style=\"font-size: smaller;\">" .. cur_display .. "</span>"
end
-- Link to previous number
local prev_data = m_data.numbers[cur_num - 1]
local prev_display = ""
if prev_data and prev_data[cur_type] then
prev_display = m_links.full_link(prev_data[cur_type], " < " .. (cur_num - 1), lang, nil, nil, nil, {tr = "-"}, false)
end
-- Link to next number
local next_data = m_data.numbers[cur_num + 1]
local next_display = ""
if next_data and next_data[cur_type] then
next_display = m_links.full_link(next_data[cur_type], (cur_num + 1) .. " > ", lang, nil, nil, nil, {tr = "-"}, false)
end
-- Link to number times ten and divided by ten
-- Show this only if the number is a power of ten times a number 1-9 (that is, of the form x000...)
local up_display
local down_display
-- This test *could* be done numerically, but this is nice and simple and it works.
if mw.ustring.find(tostring(cur_num), "^[1-9]0*$") then
local up_data = m_data.numbers[cur_num * 10]
if up_data and up_data[cur_type] then
up_display = m_links.full_link(up_data[cur_type], (cur_num * 10), lang, nil, nil, nil, {tr = "-"}, false)
end
-- Only divide by 10 if the number is at least 10
if cur_num >= 10 then
local down_data = m_data.numbers[cur_num / 10]
if down_data and down_data[cur_type] then
down_display = m_links.full_link(down_data[cur_type], (cur_num / 10), lang, nil, nil, nil, {tr = "-"}, false)
end
end
end
return [=[{| class="floatright" cellpadding="5" cellspacing="0" style="background: #ffffff; border: 1px #aaa solid; border-collapse: collapse; margin-top: .5em;" rules="all"
|+ ''']=] .. lang:getCanonicalName() .. [=[ numbers'''
]=] .. (up_display and [=[|- style="text-align: center; background:#dddddd;"
|
| style="font-size:smaller;" | ]=] .. up_display .. [=[
|
]=] or "") .. [=[|- style="text-align: center;"
| style="min-width: 6em; font-size:smaller; background:#dddddd;" | ]=] .. prev_display .. [=[
! style="min-width: 6em; font-size:larger;" | ]=] .. cur_display .. [=[
| style="min-width: 6em; font-size:smaller; background:#dddddd;" | ]=] .. next_display .. [=[
]=] .. (down_display and [=[|- style="text-align: center; background:#dddddd;"
|
| style="font-size:smaller;" | ]=] .. down_display .. [=[
|
]=] or "") .. [=[|-
| colspan="3" | ]=] .. table.concat(forms, "<br/>") .. [=[
|}]=]
end
function export.show_box_manual(frame)
local m_links = require("Module:links")
local num_type = frame.args["type"]
local args = {}
--cloning parent's args while also assigning nil to empty strings
for pname, param in pairs(frame:getParent().args) do
if param == "" then args[pname] = nil
else args[pname] = param
end
end
local lang = args[1] or (mw.title.getCurrentTitle().nsText == "Template" and "und") or error("Language code has not been specified. Please pass parameter 1 to the template.")
local sc = args["sc"];
local headlink = args["headlink"]
local wplink = args["wplink"]
local alt = args["alt"]
local prev_symbol = args[2]; if prev_symbol and mw.text.trim(prev_symbol) == "" then prev_symbol = nil end
local cur_symbol = args[3]; if cur_symbol and mw.text.trim(cur_symbol) == "" then cur_symbol = nil end
local next_symbol = args[4]; if next_symbol and mw.text.trim(next_symbol) == "" then next_symbol = nil end
local prev_term = args[5]; if prev_term and mw.text.trim(prev_term) == "" then prev_term = nil end
local next_term = args[6]; if next_term and mw.text.trim(next_term) == "" then next_term = nil end
local cardinal_term = args["card"]; local cardinal_alt = args["cardalt"]
local ordinal_term = args["ord"]; local ordinal_alt = args["ordalt"]
local adverbial_term = args["adv"]; local adverbial_alt = args["advalt"]
local multiplier_term = args["mult"]; local multiplier_alt = args["multalt"]
local distributive_term = args["dis"]; local distributive_alt = args["disalt"]
local collective_term = args["coll"]; local collective_alt = args["collalt"]
local optional1_title = args["opt"]
local optional1_term = args["optx"]; local optional1_alt = args["optxalt"]
local optional2_title = args["opt2"]
local optional2_term = args["opt2x"]; local optional2_alt = args["opt2xalt"]
lang = require("Module:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
sc = (sc and (require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
require("Module:debug").track("number list/" .. lang:getCode())
if sc then
require("Module:debug").track("number list/sc")
end
if headlink then
require("Module:debug").track("number list/headlink")
end
if wplink then
require("Module:debug").track("number list/wplink")
end
if alt then
require("Module:debug").track("number list/alt")
end
if cardinal_alt or ordinal_alt or adverbial_alt or multiplier_alt or distributive_alt or collective_alt or optional1_alt or optional2_alt then
require("Module:debug").track("number list/xalt")
end
local is_reconstructed = lang:getType() == "reconstructed" or (lang:getType() ~= "appendix-constructed" and mw.title.getCurrentTitle().nsText == "Appendix")
alt = alt or (is_reconstructed and "*" or "") .. mw.title.getCurrentTitle().subpageText
if num_type == "cardinal" then
cardinal_term = (is_reconstructed and "*" or "") .. mw.title.getCurrentTitle().subpageText
cardinal_alt = alt
elseif num_type == "ordinal" then
ordinal_term = (is_reconstructed and "*" or "") .. mw.title.getCurrentTitle().subpageText
ordinal_alt = alt
end
local header = lang:getCanonicalName() .. " " .. num_type .. " numbers"
if headlink then
header = "[[" .. headlink .. "|" .. header .. "]]"
end
local previous = ""
if prev_term or prev_symbol then
previous = m_links.full_link(prev_term, " < " .. prev_symbol, lang, sc, nil, nil, {tr = "-"}, false)
end
local current = m_links.full_link(nil, cur_symbol, lang, sc, nil, nil, {tr = "-"}, false)
local next = ""
if next_term or next_symbol then
next = m_links.full_link(next_term, next_symbol .. " > ", lang, sc, nil, nil, {tr = "-"}, false)
end
local forms = {}
if cardinal_term then
table.insert(forms, " ''[[cardinal number|Cardinal]]'' : " .. m_links.full_link(cardinal_term, cardinal_alt, lang, sc, nil, nil, false))
end
if ordinal_term then
table.insert(forms, " ''[[ordinal number|Ordinal]]'' : " .. m_links.full_link(ordinal_term, ordinal_alt, lang, sc, nil, nil, false))
end
if adverbial_term then
table.insert(forms, " ''[[adverbial number|Adverbial]]'' : " .. m_links.full_link(adverbial_term, adverbial_alt, lang, sc, nil, nil, false))
end
if multiplier_term then
table.insert(forms, " ''[[multiplier|Multiplier]]'' : " .. m_links.full_link(multiplier_term, multiplier_alt, lang, sc, nil, nil, false))
end
if distributive_term then
table.insert(forms, " ''[[distributive number|Distributive]]'' : " .. m_links.full_link(distributive_term, distributive_alt, lang, sc, nil, nil, false))
end
if collective_term then
table.insert(forms, " ''[[collective number|Collective]]'' : " .. m_links.full_link(collective_term, collective_alt, lang, sc, nil, nil, false))
end
if optional1_title then
table.insert(forms, " ''" .. optional1_title .. "'' : " .. m_links.full_link(optional1_term, optional1_alt, lang, sc, nil, nil, false))
end
if optional2_title then
table.insert(forms, " ''" .. optional2_title .. "'' : " .. m_links.full_link(optional2_term, optional2_alt, lang, sc, nil, nil, false))
end
local footer = ""
if wplink then
footer =
"[[w:" .. lang:getCode() .. ":Main Page|" .. lang:getCanonicalName() .. " Wikipedia]] article on " ..
m_links.full_link("w:" .. lang:getCode() .. ":" .. wplink, alt, lang, sc, nil, nil, false)
end
return [=[{| class="floatright" cellpadding="5" cellspacing="0" style="background: #ffffff; border: 1px #aaa solid; border-collapse: collapse; margin-top: .5em;" rules="all"
|+ ''']=] .. header .. [=['''
|-
| style="width: 64px; background:#dddddd; text-align: center; font-size:smaller;" | ]=] .. previous .. [=[
! style="width: 98px; text-align: center; font-size:larger;" | ]=] .. current .. [=[
| style="width: 64px; text-align: center; background:#dddddd; font-size:smaller;" | ]=] .. next .. [=[
|-
| colspan="3" | ]=] .. table.concat(forms, "<br/>") .. [=[
|-
| colspan="3" style="text-align: center; background: #dddddd;" | ]=] .. footer .. [=[
|}]=]
end
return export