Module:L
Usage
[edit]This module has one method, main: {{#invoke:L|main| ... }}.
For more information, see Template:Lexeme.
| Uses Lua: |
This template helps inserting Wikibase lexemes and forms and senses
| Parameter | Description | Type | Status | |
|---|---|---|---|---|
| ID | 1 | The lexeme ID, with or without the “L” prefix. May also be a form ID.
| Line | required |
| add anchor | anchor | If set to any non-empty value, the template creates an anchor with the lexeme ID (always prefixed with “L”) | Line | optional |
| show ID | show_l | If set to “no”, the lexeme ID isn’t shown (only the lemma) | Line | optional |
| short | short | Display only the form or sense ID, for example (S1) instead of (L123-S1)
| String | optional |
| s | s | Display glosses for senses
| String | optional |
| lang | lang | The language of the glosses you want to display
| String | optional |
Examples
[edit]{{L|L1}}→ ama/𒂼 (L1){{L|1}}→ ama/𒂼 (L1){{L|L3341}}→ child (L3341){{L|L1474373}}→ عَزَمَ (L1474373)
forms
[edit]{{L|L3341-F2}}→ children (L3341-F2){{L|L3341-F4}}→ children's (L3341-F4){{L|L1474373-F58}}→ عُزِمَ (L1474373-F58){{L|L1474373-F2}}→ عَزَمَا (L1474373-F2)
short
[edit]{{L|L1474373-F58}}→ عُزِمَ (L1474373-F58){{L|L1474373-F2|short=1}}→ عَزَمَا (F2)
Senses
[edit]Ids
[edit]{{L|L1-S1}}→ ama/𒂼 (L1-S1){{L|L1-S1|short=1}}→ ama/𒂼 (S1)
Glosses
[edit]{{L|L1-S1|s=1}}→ madre (L1-S1){{L|L1-S1|short=1|s=1}}→ madre (S1)
Languages
[edit]{{L|L1-S1|short=1|s=1}}→ madre (S1){{L|L1-S1|short=1|s=1|lang=en}}→ mother (S1){{L|L1-S1|short=1|s=1|lang=ar}}→ أم (S1)
See also
[edit]| Template | Shorthand | Example |
|---|---|---|
{{Autodescription}} |
{{A}} |
totality consisting of space, time, matter and energy |
{{Data}} |
||
{{EntitySchema}} |
{{E}} |
|
{{Label}} |
Douglas Adams | |
{{LinkedLabel}} |
Douglas Adams | |
{{Label and description}} |
{{LD}} |
Douglas Adams (British science fiction writer and humorist (1952–2001)) |
{{Item Link with Tooltip}} |
{{LT}} |
D. Adams |
{{Q}} |
Douglas Adams (Q42) | |
{{Q+}} |
Douglas Adams (Q42): British science fiction writer and humorist (1952–2001) | |
{{Q'}} |
Douglas Adams (Q42) | |
{{Q''}} |
Douglas Adams (Q42) | |
{{Q'''}} |
Douglas Adams (Q42) | |
{{Q!}} |
||
{{Q*}} |
||
{{Q(}} |
Douglas Adams (Q42) | |
{{QB}} |
Douglas Adams (Q42); talk | |
{{QP}} |
instance of (P31) of Douglas Adams (Q42) | |
{{QT}} |
Douglas Adams (Q42) | |
{{Property}} |
{{P}} |
country (P17) |
{{P'}} |
country (P17) | |
{{PT'}} |
country | |
{{P+}} |
country (P17): sovereign state that this item is in (not to be used for human beings) | |
{{Lexeme}} |
{{L}} |
|
{{Claim}} |
{{C}} |
|
{{Statement}} |
{{St}} |
|
{{Statement+}} |
||
{{EzStatement+}} |
||
| (Label in Venetian) | {{Qvec}} |
Douglas Adams(42) |
| (Label in Taraškievica) | {{Qbe-tarask}} |
Дуглас Адамз(42) |
| (Label in English) | {{Qen}} |
Douglas Adams(42) |
| (Label in French) | {{Qfr}} |
Douglas Adams(42) |
| (Label in Italian) | {{Qit}} |
Douglas Adams(42) |
| (Label in German) | {{Qde}} |
Douglas Adams(42) |
| (Label in Polish) | {{Qpl}} |
Douglas Adams(42) |
| (Label in Russian) | {{Qru}} |
Дуглас Адамс(42) |
| (Label in Ukrainian) | {{Quk}} |
Дуглас Адамс(42) |
| (Label in Spanish) | {{Qes}} |
Douglas Adams(42) |
| (Label in Chinese) | {{Qzh}} |
道格拉斯·亞當斯(42) |
| (Label in Shahmukhi) | {{Qpnb}} |
ڈگلس ایڈمس(42) |
| (Label in Gurmukhi) | {{Qpa}} |
ਡਗਲਸ ਐਡਮਸ(42) |
| (Label in Saraiki) | {{Qskr}} |
ڈگلس ایڈمس(42) |
| (Label in Swedish) | {{Qsv}} |
Douglas Adams(42) |
Code
local p = {}
local i18nmessages = mw.loadData('Module:i18n/wikidata')
local fb = require('Module:Fallback')
local defaultlang = mw.getCurrentFrame():preprocess("{{int:lang}}")
local function i18n(str)
local message = i18nmessages[str]
if type(message) == 'string' then
return message
end
return fb._langSwitch(message, defaultlang) .. ''
end
local function anchor(id)
return string.format('<span class="anchor" id="%s"></span>', id)
end
-- Returns the lemmas of the entity concatenated with '/'.
local function getLemma(entity) -- simple for simple templates like {{Q|}}}
if not entity then
return i18n('invalid-id')
end
local lemmas = ''
local function valuesSortedByLanguage(t)
local values = {}
for k, v in pairs(t) do
values[#values + 1] = v
end
table.sort(values,
function(a, b)
return (a.language < b.language)
end)
local i = 0
return function()
i = i + 1
if values[i] then
return values[i]
end
end
end
if entity.lemmas then
for v in valuesSortedByLanguage(entity.lemmas) do
if lemmas ~= '' then
lemmas = lemmas .. '/' .. '<span lang=' .. v.language .. ' dir="auto">' .. v.value .. '</span>'
else
lemmas = '<span lang=' .. v.language .. ' dir="auto">' .. v.value .. '</span>'
end
end
end
return lemmas
end
local function lemma_value(id)
-- return mw.getCurrentFrame():expandTemplate { title = "lemma", args = { id } }
return getLemma(mw.wikibase.getEntity(id))
end
local function getSenses(lexemeId, Sid, senLang)
local gloss_text = ''
local entity = mw.wikibase.getEntity(lexemeId)
for _, sense in pairs(entity:getSenses()) do
local lexemeId, subId = mw.wikibase.lexeme.splitLexemeId(sense.id)
if lexemeId == lexemeId and subId == Sid then
-- "glosses": { "en": { "language": "en", "value": "human between the stages of birth and puberty" } }
-- glosses = sense:getGlosses()
if senLang then
gloss_text = sense.glosses[senLang].value
else
for j, gloss in pairs(sense.glosses) do
gloss_text = gloss.value
break
end
end
break
end
end
return gloss_text
end
local function getFormRepFromEntity(entity)
local function valuesSortedByLanguage(t)
local values = {}
for k, v in pairs(t) do
values[#values + 1] = v
end
table.sort(values,
function(a, b)
return (a[2] < b[2])
end)
local i = 0
return function()
i = i + 1
if values[i] then
return values[i]
end
end
end
local lemmas = ''
for v in valuesSortedByLanguage(entity:getRepresentations()) do
if lemmas ~= '' then
lemmas = lemmas .. '/' .. v[1]
else
lemmas = v[1]
end
end
return lemmas
end
local function getLinkAndDisplay(id, showSen, senLang)
local lexemeId, subId = mw.wikibase.lexeme.splitLexemeId(id)
if not subId then
-- only Lexeme
return "Lexeme:" .. id, lemma_value(id)
end
local link = "Lexeme:" .. lexemeId .. "#" .. subId
local display
if subId:sub(1, 1) == "F" then
-- display = frame:callParserFunction { name = "#invoke", args = { "Lexeme", "getFormRep", id } }
display = getFormRepFromEntity(mw.wikibase.getEntity(id))
elseif subId:sub(1, 1) == "S" and showSen then
display = getSenses(lexemeId, subId, senLang)
else
display = lemma_value(lexemeId)
end
return link, display
end
local function getDisplay2(id, show_l, short)
if show_l == "no" then return nil end
if short == "1" then
local _, subId = mw.wikibase.lexeme.splitLexemeId(id)
if subId then
return subId -- part F or S
end
end
return id
end
function p._main(args, frame)
local id = mw.text.trim(args[1] or "")
if id == "" then return "" end
-- if id start with numbers
if id:sub(1, 1):match("%d") then
id = "L" .. id
end
local showSen = args["s"]
local senLang = args["lang"]
local link, display = getLinkAndDisplay(id, showSen, senLang)
local display2 = getDisplay2(id, args["show_l"], args["short"])
local anchorValue = (args["anchor"] and args["anchor"] ~= "") and anchor("Lexeme:" .. id) or ""
local fullDisplay = display .. (display2 and " <small>(" .. display2 .. ")</small>" or "")
return string.format('%s[[%s|%s]]', anchorValue, link, fullDisplay)
end
function p.main(frame)
return p._main(frame:getParent().args, frame)
end
function p.test(frame)
return p._main(frame.args, frame)
end
function p.getSenses(frame)
return getSenses(frame.args[1], frame.args[2])
end
return p