Modul:Pronunciation
Documentația acestui modul poate fi creată la Modul:Pronunciation/doc
local getArgs = require('Modul:Arguments').getArgs
local wikidata = require('Modul:Wikidata')
local getLangLink = require('Modul:InLang').getLangLink
local TableTools = require('Modul:TableTools')
local StringUtils = require('Modul:StringUtils')
local p = {}
local function extractValueAndLangFromClaim(q, propId)
local claims = wikidata.findBestClaimsForProperty(q, propId)
local array = {}
if claims then
for _,eachClaim in ipairs(claims) do
if eachClaim.type == 'statement' and eachClaim.mainsnak.snaktype == 'value' then
local audioLang = '_'
if eachClaim.qualifiers and eachClaim.qualifiers['P407'] then
for __,eachLangQual in ipairs(eachClaim.qualifiers['P407']) do
if eachLangQual.snaktype == 'value' then
audioLang = eachLangQual.datavalue.value.id
break
end
end
end
array[audioLang] = eachClaim.mainsnak.datavalue.value
end
end
end
return array
end
p.fromArgs = function(q, langs, hideLangName)
q = q or mw.wikibase.getEntityIdForCurrentPage()
if langs and 0 < #langs then
for langIdx=1,#langs do
langs[langIdx] = mw.text.trim(langs[langIdx])
end
else
local langClaims = {}
TableTools.appendAll(langClaims, wikidata.findBestClaimsForProperty(q, 'P37') or {})
TableTools.appendAll(langClaims, wikidata.findBestClaimsForProperty(q, 'P103') or {})
TableTools.appendAll(langClaims, wikidata.findBestClaimsForProperty(q, 'P364') or {})
local itemCountryQId = wikidata.loadOneValueInChain({q, 'P17', 'raw'})
if itemCountryQId and mw.ustring.len(itemCountryQId) > 0 then
TableTools.appendAll(langClaims, wikidata.findBestClaimsForProperty(itemCountryQId, 'P37'))
end
for _,eachLangClaim in ipairs(langClaims) do
if eachLangClaim.type == 'statement' and eachLangClaim.mainsnak.snaktype == 'value' then
table.insert(langs, eachLangClaim.mainsnak.datavalue.value.id)
end
end
end
local elem = mw.html.create('span')
:addClass('unicode')
:addClass('haudio')
:tag('span')
:addClass('fn')
:tag('span')
:css('white-space', 'no-wrap')
local wikitext = ''
local pronAudio = extractValueAndLangFromClaim(q, 'P443')
local pronIPA = extractValueAndLangFromClaim(q, 'P898')
local pronData = {}
local langProns = {}
for eachLangQID,eachLangData in pairs(pronAudio) do
if 0 < #langs and TableTools.contains(langs, eachLangQID) then
if not pronData[eachLangQID] then pronData[eachLangQID] = {} end
pronData[eachLangQID].audio = eachLangData
end
end
for eachLangQID,eachLangData in pairs(pronIPA) do
if 0 < #langs and TableTools.contains(langs, eachLangQID) then
if not pronData[eachLangQID] then pronData[eachLangQID] = {} end
pronData[eachLangQID].ipa = eachLangData
end
end
for eachLangQID,eachLangData in pairs(pronData) do
local langString = ''
if not hideLangName and '_' ~= eachLangQID then
langString = getLangLink(eachLangQID) .. ':'
end
if eachLangData.audio then
langString = langString .. ' [[Fișier:Loudspeaker.svg|11px|link=Fișier:' .. eachLangData.audio .. '|Pronunție audio]]'
end
if eachLangData.ipa then
langString = langString .. ' ' .. tostring(mw.html.create('span'):attr('title', 'Notație în Alfabetul Fonetic Internațional'):wikitext('[[Alfabetul Fonetic Internațional|/' .. eachLangData.ipa .. '/]]'))
elseif eachLangData.audio then
langString = langString .. ' [[:Fișier:' .. eachLangData.audio .. '|audio]]'
end
table.insert(langProns, mw.text.trim(langString))
end
local outText = StringUtils._prependToString({StringUtils._emptyToNil({table.concat(langProns, '; ')}), 'pronunție '})
if outText and outText ~= '' then
elem:wikitext(outText)
return tostring(elem)
else
return ''
end
end
p.fromArray = function(array)
local langs = {}
if array and array.langs then
langs = mw.text.split(array.langs, ',')
end
return p.fromArgs(array and array.q, langs, array and (array.hidelangname or array['ascunde_limba']))
end
p.fromFrame = function(frame)
return p.fromArray(getArgs(frame))
end
return p