Modul:Geburtsort: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
| Zeile 1: | Zeile 1: | ||
-- Modul:Geburtsort | |||
-- Benutzung in Vorlage: {{#invoke:Geburtsort|render|value={{{Geburtsort}}}|link=category}} | |||
-- link=page (Standard) → auf Artikelseiten verlinken | |||
-- link=category → sichtbare Links zeigen direkt auf die Kategorien | |||
local p = {} | |||
local trim = mw.text.trim | |||
local lc = mw.ustring.lower | |||
-- Link, wenn Seite existiert; sonst Plaintext | |||
local function linkIfExists(titleText) | |||
if not titleText or titleText == "" then return "" end | |||
local title = mw.title.new(titleText) | |||
if title and title.exists then | |||
return string.format("[[%s]]", titleText) | |||
end | |||
return titleText | |||
end | |||
-- Länder-Normalisierung | |||
local countryNormalize = (function() | |||
local map = {} | |||
local function add(canonical, variants) | |||
for _, v in ipairs(variants) do map[lc(v)] = canonical end | |||
end | |||
add("Deutschland", {"Deutschland","BRD","deutschland"}) | |||
add("USA", {"USA","Vereinigte Staaten","United States","US","Amerika","US-Amerika","vereinigte staaten"}) | |||
add("Großbritannien", {"Großbritannien","Grossbritannien","Vereinigtes Königreich","United Kingdom","UK","England","gb"}) | |||
add("Österreich", {"Österreich","Oesterreich","österreich","oesterreich"}) | |||
add("Schweiz", {"Schweiz"}) | |||
add("Frankreich", {"Frankreich"}) | |||
add("Italien", {"Italien"}) | |||
add("Spanien", {"Spanien"}) | |||
add("Niederlande", {"Niederlande","Holland"}) | |||
add("Kanada", {"Kanada"}) | |||
add("Belgien", {"Belgien"}) | |||
add("Dänemark", {"Dänemark","Daenemark"}) | |||
add("Schweden", {"Schweden"}) | |||
add("Norwegen", {"Norwegen"}) | |||
return map | |||
end)() | |||
-- Länderkategorie (mit Beugung nach "Geboren in ") | |||
local countryCatSuffix = { | |||
["Deutschland"] = "Deutschland", | |||
["USA"] = "den USA", | |||
["Großbritannien"] = "Großbritannien", | |||
["Österreich"] = "Österreich", | |||
["Schweiz"] = "der Schweiz", | |||
["Frankreich"] = "Frankreich", | |||
["Italien"] = "Italien", | |||
["Spanien"] = "Spanien", | |||
["Niederlande"] = "den Niederlanden", | |||
["Kanada"] = "Kanada", | |||
["Belgien"] = "Belgien", | |||
["Dänemark"] = "Dänemark", | |||
["Schweden"] = "Schweden", | |||
["Norwegen"] = "Norwegen", | |||
} | |||
-- "Stadt, Land" am ersten Komma trennen | |||
local function splitCityCountry(s) | |||
local parts = mw.text.split(s, ",", true) | |||
local city = trim(parts[1] or "") | |||
local country = "" | |||
if #parts >= 2 then | |||
local rest = {} | |||
for i = 2, #parts do rest[#rest+1] = parts[i] end | |||
country = trim(table.concat(rest, ",")) | |||
end | |||
return city, country | |||
end | |||
function p.render(frame) | function p.render(frame) | ||
local value = frame.args.value or | -- Parameter lesen | ||
local value = frame.args.value | |||
if (not value or value == "") and frame.getParent then | |||
local parent = frame:getParent() | |||
if parent then value = parent.args.value end | |||
end | |||
value = value and trim(value) or "" | value = value and trim(value) or "" | ||
if value == "" then return "" end | if value == "" then return "" end | ||
| Zeile 6: | Zeile 85: | ||
local linkMode = (frame.args.link or ""):lower() -- "page" (default) oder "category" | local linkMode = (frame.args.link or ""):lower() -- "page" (default) oder "category" | ||
-- | -- Parsen & normalisieren | ||
local city, countryRaw = splitCityCountry(value) | local city, countryRaw = splitCityCountry(value) | ||
local countryNorm = nil | local countryNorm = nil | ||
if countryRaw ~= "" then | if countryRaw ~= "" then | ||
| Zeile 15: | Zeile 92: | ||
end | end | ||
-- Anzeige-Links | -- Anzeige-Links | ||
local cityView, countryView | local cityView, countryView | ||
if linkMode == "category" then | if linkMode == "category" then | ||
cityView = (city ~= "") and string.format("[[:Kategorie:Geboren in %s|%s]]", city, city) or "" | |||
cityView = city ~= "" and string.format("[[:Kategorie:Geboren in %s|%s]]", city, city) or "" | |||
if countryNorm and countryNorm ~= "" then | if countryNorm and countryNorm ~= "" then | ||
local suffix = countryCatSuffix[countryNorm] or countryNorm | local suffix = countryCatSuffix[countryNorm] or countryNorm | ||
| Zeile 28: | Zeile 103: | ||
end | end | ||
else | else | ||
cityView = linkIfExists(city) | |||
cityView = linkIfExists(city) | |||
countryView = (countryNorm and linkIfExists(countryNorm)) or "" | countryView = (countryNorm and linkIfExists(countryNorm)) or "" | ||
end | end | ||
-- | -- Ausgabe zusammensetzen | ||
local out = {} | local out = {} | ||
out[#out+1] = cityView | out[#out+1] = cityView | ||
| Zeile 40: | Zeile 114: | ||
end | end | ||
-- Kategorien | -- Kategorien setzen | ||
if city ~= "" then | if city ~= "" then | ||
out[#out+1] = string.format("\n[[Kategorie:Geboren in %s]]", city) | out[#out+1] = string.format("\n[[Kategorie:Geboren in %s]]", city) | ||
| Zeile 51: | Zeile 125: | ||
return table.concat(out) | return table.concat(out) | ||
end | end | ||
return p | |||
Aktuelle Version vom 4. Oktober 2025, 09:49 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Geburtsort/Doku erstellt werden
-- Modul:Geburtsort
-- Benutzung in Vorlage: {{#invoke:Geburtsort|render|value={{{Geburtsort}}}|link=category}}
-- link=page (Standard) → auf Artikelseiten verlinken
-- link=category → sichtbare Links zeigen direkt auf die Kategorien
local p = {}
local trim = mw.text.trim
local lc = mw.ustring.lower
-- Link, wenn Seite existiert; sonst Plaintext
local function linkIfExists(titleText)
if not titleText or titleText == "" then return "" end
local title = mw.title.new(titleText)
if title and title.exists then
return string.format("[[%s]]", titleText)
end
return titleText
end
-- Länder-Normalisierung
local countryNormalize = (function()
local map = {}
local function add(canonical, variants)
for _, v in ipairs(variants) do map[lc(v)] = canonical end
end
add("Deutschland", {"Deutschland","BRD","deutschland"})
add("USA", {"USA","Vereinigte Staaten","United States","US","Amerika","US-Amerika","vereinigte staaten"})
add("Großbritannien", {"Großbritannien","Grossbritannien","Vereinigtes Königreich","United Kingdom","UK","England","gb"})
add("Österreich", {"Österreich","Oesterreich","österreich","oesterreich"})
add("Schweiz", {"Schweiz"})
add("Frankreich", {"Frankreich"})
add("Italien", {"Italien"})
add("Spanien", {"Spanien"})
add("Niederlande", {"Niederlande","Holland"})
add("Kanada", {"Kanada"})
add("Belgien", {"Belgien"})
add("Dänemark", {"Dänemark","Daenemark"})
add("Schweden", {"Schweden"})
add("Norwegen", {"Norwegen"})
return map
end)()
-- Länderkategorie (mit Beugung nach "Geboren in ")
local countryCatSuffix = {
["Deutschland"] = "Deutschland",
["USA"] = "den USA",
["Großbritannien"] = "Großbritannien",
["Österreich"] = "Österreich",
["Schweiz"] = "der Schweiz",
["Frankreich"] = "Frankreich",
["Italien"] = "Italien",
["Spanien"] = "Spanien",
["Niederlande"] = "den Niederlanden",
["Kanada"] = "Kanada",
["Belgien"] = "Belgien",
["Dänemark"] = "Dänemark",
["Schweden"] = "Schweden",
["Norwegen"] = "Norwegen",
}
-- "Stadt, Land" am ersten Komma trennen
local function splitCityCountry(s)
local parts = mw.text.split(s, ",", true)
local city = trim(parts[1] or "")
local country = ""
if #parts >= 2 then
local rest = {}
for i = 2, #parts do rest[#rest+1] = parts[i] end
country = trim(table.concat(rest, ","))
end
return city, country
end
function p.render(frame)
-- Parameter lesen
local value = frame.args.value
if (not value or value == "") and frame.getParent then
local parent = frame:getParent()
if parent then value = parent.args.value end
end
value = value and trim(value) or ""
if value == "" then return "" end
local linkMode = (frame.args.link or ""):lower() -- "page" (default) oder "category"
-- Parsen & normalisieren
local city, countryRaw = splitCityCountry(value)
local countryNorm = nil
if countryRaw ~= "" then
countryNorm = countryNormalize[lc(countryRaw)] or countryRaw
end
-- Anzeige-Links
local cityView, countryView
if linkMode == "category" then
cityView = (city ~= "") and string.format("[[:Kategorie:Geboren in %s|%s]]", city, city) or ""
if countryNorm and countryNorm ~= "" then
local suffix = countryCatSuffix[countryNorm] or countryNorm
countryView = string.format("[[:Kategorie:Geboren in %s|%s]]", suffix, countryNorm)
else
countryView = ""
end
else
cityView = linkIfExists(city)
countryView = (countryNorm and linkIfExists(countryNorm)) or ""
end
-- Ausgabe zusammensetzen
local out = {}
out[#out+1] = cityView
if countryView ~= "" then
out[#out+1] = ", " .. countryView
end
-- Kategorien setzen
if city ~= "" then
out[#out+1] = string.format("\n[[Kategorie:Geboren in %s]]", city)
end
if countryNorm and countryNorm ~= "" then
local suffix = countryCatSuffix[countryNorm] or countryNorm
out[#out+1] = string.format("\n[[Kategorie:Geboren in %s]]", suffix)
end
return table.concat(out)
end
return p