Modul:NativeName
Aspect
Documentația acestui modul poate fi creată la Modul:NativeName/doc
local p = {}
local Wikidata = require('Modul:Wikidata')
local Lang = require('Modul:Lang')
local langData = mw.loadData('Modul:Lang/data/iana')
local getArgs = require('Modul:Arguments').getArgs
local StringUtils = require('Modul:StringUtils')
local TableTools = require('Modul:TableTools')
local _nbsp_ = mw.text.decode(' ')
local _br_ = tostring(mw.html.create('br'))
local encloseString = function(str, left, right) return StringUtils._encloseString({str, left, right}) end
local emptyToNil = function(str) return StringUtils._emptyToNil({str}) end
local function fromWikidata(qid)
local nativeNamesClaims = Wikidata.findBestClaimsForProperty(qid, 'P1705')
local ret = {}
if nativeNamesClaims then
local nativeNamesList = {}
for _,eachNativeNamesClaims in ipairs(nativeNamesClaims) do
if eachNativeNamesClaims.type == 'statement' and eachNativeNamesClaims.mainsnak.snaktype == 'value'
then
ret[eachNativeNamesClaims.mainsnak.datavalue.value.text] = eachNativeNamesClaims.mainsnak.datavalue.value.language
end
end
end
return ret
end
function p.fromArgs(texts, styling, script)
if TableTools.size(texts) == 0 then
texts = fromWikidata(nil)
end
local outs = {}
for text, lang in pairs(texts) do
local out = Lang.fromArgs(lang, nil, text, styling.italics)
if styling.paren then
out = out .. _nbsp_
if styling.nbsp then out = out .. _nbsp_ end
local parenElem = mw.html.create('span'):addClass('languageicon')
:css('font-weight', 'normal')
:css('font-size', styling.parensize or '81%')
local langNames = langData[lang]
if langNames and langNames[1] then
local langName = langNames[1]
local langLink
if langName then
langLink = styling.nolink and langName or ("[[Limba " .. langName .. "|" .. langName .. "]]")
parenElem:wikitext(encloseString(langLink, '(', ')'))
out = out .. tostring(parenElem)
end
end
end
table.insert(outs, out)
end
return table.concat(outs, _br_)
end
function p.fromArray(args)
local lang = args[1]
local text = args[2]
local texts = {}
if emptyToNil(text) and emptyToNil(lang) then
texts[text] = lang
end
local styling = {}
local argitalics = emptyToNil(args.italics) or args.italic
styling.italics = argitalics ~= 'off' and argitalics ~= 'no'
local argparen = emptyToNil(args.paren) or args.icon
styling.paren = argparen ~= 'off' and argparen ~= 'omit' and argparen ~= 'no'
styling.nolink = args.nolink ~= nil
styling.nbsp = args.nbsp ~= 'off' and args.nbsp ~= 'omit'
styling.parensize = emptyToNil(args.parensize) or emptyToNil(args.fontsize)
script = emptyToNil(args.script)
return p.fromArgs(texts, styling, script)
end
function p.fromFrame(frame)
local args = getArgs(frame)
return p.fromArray(args)
end
return p