Difference between revisions of "Module:Sandbox/Galobtter/Short description from country"
< Module:Sandbox | Galobtter
Jump to navigation
Jump to search
blackwiki>Galobtter (aaargh) |
m (10 revisions imported) |
||
| (3 intermediate revisions by one other user not shown) | |||
| Line 1: | Line 1: | ||
| − | --given a pattern input like "country%d", if there is only one of it (excluding youth teams of the same country etc), give "nationality profession", e.g "German | + | --given a pattern input like "country%d", if there is only one of it (excluding youth teams of the same country etc), give "nationality profession", e.g "German footballer" |
--data = mw.loaddata("Module:Short description from country/data") | --data = mw.loaddata("Module:Short description from country/data") | ||
| Line 12: | Line 12: | ||
local parentArgs = getArgs(frame, {'parentOnly'}) | local parentArgs = getArgs(frame, {'parentOnly'}) | ||
local name = args[1] | local name = args[1] | ||
| − | |||
local nationatString | local nationatString | ||
for m, n in pairs (parentArgs) do | for m, n in pairs (parentArgs) do | ||
if string.find(m, "^"..name.."$") then | if string.find(m, "^"..name.."$") then | ||
| − | n = string.gsub(n, " U[-]?%d+ | + | n = require('Module:Plain text').main(n) --remove links and get the text to make it easier to process |
| − | + | n = string.gsub(n, " U[-]?%d+?", "") --strip U23/U17 etc | |
| − | if nationString | + | --if previous nationstring, check if new nationstring |
| − | + | --for detecting cases where the person plays | |
| − | + | --for different countries, and thus cannot determine nationality | |
| − | + | if nationString and (n ~= nationString) then | |
| + | return | ||
else | else | ||
nationString = n | nationString = n | ||
| Line 27: | Line 27: | ||
end | end | ||
end | end | ||
| − | if nationString then return nationString.." "..args[2] end --data[nationString] | + | if nationString then return nationString.." "..args[2] end --should return data[nationString], to get denonym and to check if real nation/valid input |
end | end | ||
return p | return p | ||
Latest revision as of 09:47, 27 September 2020
Documentation for this module may be created at Module:Sandbox/Galobtter/Short description from country/doc
--given a pattern input like "country%d", if there is only one of it (excluding youth teams of the same country etc), give "nationality profession", e.g "German footballer"
--data = mw.loaddata("Module:Short description from country/data")
local p = {}
function p.main (frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame, {'frameOnly'})
if args.disable == 'yes' then
return
end
local parentArgs = getArgs(frame, {'parentOnly'})
local name = args[1]
local nationatString
for m, n in pairs (parentArgs) do
if string.find(m, "^"..name.."$") then
n = require('Module:Plain text').main(n) --remove links and get the text to make it easier to process
n = string.gsub(n, " U[-]?%d+?", "") --strip U23/U17 etc
--if previous nationstring, check if new nationstring
--for detecting cases where the person plays
--for different countries, and thus cannot determine nationality
if nationString and (n ~= nationString) then
return
else
nationString = n
end
end
end
if nationString then return nationString.." "..args[2] end --should return data[nationString], to get denonym and to check if real nation/valid input
end
return p