Modul:Settlement short description
Qiyofa
Bu moduldan koʻplab sahifada foydalanilgan. Tajriba oʻtkazish uchun modulning /qumloq yoki /test ostsahifalaridan foydalaning. Oʻzgarishlar kiritishdan avval boshqa foydalanuvchilar bilan muhokama qilish haqida oʻylab koʻring. |
Bu andoza quyidagi Luadan foydalanadi: |
Used in Andoza:Turar-joy bilgiqutisi to generate short descriptions.
--generates auto short description for use in infobox settlement
local p = {}
p.categories = ""
local plain = require('Module:Plain text')._main
local getArgs = require('Module:Arguments').getArgs
local tableTools = require ('Module:TableTools')
function p.reverseTable (init)
init[1], init[3] = init[3], init[1]
return init
end
function p.assign (args, argname, num)
local val
local var = {}
for i = 0,num do
if i == 0 then
val = ""
else
val = tostring(i)
end
var[i+1] = p.validate(plain(args[argname..val]))
end
return var
end
function p.shortdesc(text, frame)
return frame:expandTemplate{title = '', args = {text, 'noreplace'}}
end
function p.category (cattype)
local category = string.format('', cattype)
if category then p.categories = p.categories..category end --categorize
end
--sanity and other checks
function p.validate (parameter, cat)
if not parameter then return nil end
parameter = parameter:gsub('%b()', '')
:gsub('%s+', ' ')
:gsub('^%s+', '')
:gsub('%s+$', '')
if parameter:match("[,;]") or not parameter:match("%a") then
if cat then p.category (cat) end
return nil
end
if (parameter == "") then return nil end
return parameter
end
function p.cleanupLoc (location)
if location == "" then return nil end
local replacements = {
["England, United Kingdom"] = "England",
["Scotland, United Kingdom"] = "Scotland",
["Wales, United Kingdom"] = "Wales",
["New York City, New York, United States"] = "New York City",
["^United States$"] = "the United States",
["London, United Kingdom"] = "London, England"
}
for i, v in pairs(replacements) do
location = location:gsub(i, v)
end
return location
end
function p.main(frame)
local categories = ""
local subdivision_types = {}
local subdivision_names = {}
local args = getArgs (frame, {parentOnly = true})
local settlement_type = p.validate(plain(args.settlement_type or args.type), "settlement type") or "Place"
local short_description = plain(args.short_description)
subdivision_types = p.assign(args, "subdivision_type", 2)
subdivision_names = p.assign(args, "subdivision_name", 2)
if short_description then
if (short_description == 'no') then
return
else
local language = mw.language.getContentLanguage()
return p.shortdesc(language:ucfirst(short_description), frame)
end
end
if not(subdivision_names[3] and
(string.find(settlement_type, '[nN]eighbo[u]?rhood') or string.find(settlement_type, '[sS]uburb'))) then
subdivision_names[3] = nil
end
for x, y in ipairs (subdivision_types) do
local special_types = {
"Voivodeship"
}
for i, j in ipairs(special_types) do
if subdivision_names[x] and string.find(y, j, 1, true)
and not string.find(subdivision_names[x], j, 1, true) then
subdivision_names[x] = subdivision_names[x].." "..j
end
end
end
for x, y in ipairs (subdivision_names) do
if y then
if string.find(settlement_type, y, 1, true) then
subdivision_names[x] = nil
p.category ("settlement type")
end
if y == mw.title.getCurrentTitle().text then
subdivision_names[x] = nil
end
end
end
local location = table.concat(tableTools.compressSparseArray(p.reverseTable(subdivision_names)), ', ')
location = p.cleanupLoc (location)
if location then location = " in " .. location else location = "" end
local language = mw.language.getContentLanguage()
return p.shortdesc(language:ucfirst(settlement_type..location), frame)..p.categories
end
return p