Mòdulu:etimoluggìa

La ducumintazzioni di stu mòdulu si pò criari nta Mòdulu:etimoluggìa/doc

local m_basi = require('Mòdulu:basi')
local m_params = require('Mòdulu:paràmitri')
local m_lingui = require('Mòdulu:lingui')
local m_tabbella = require('Mòdulu:tabbella')
local m_Unicode_data = require('Mòdulu:dati Unicode')
local checkLang = function(langCode)
  return m_lingui.get_nom(langCode) ~= nil
end
local p = {}
function p.templateEtymologyConstruction(frame)
  local params = {
    ["tèrmini"] = { required = true },
    ["tèrmini-plurali"] = {},
    ["di"] = {},
    ["di2"] = {},
    ["tr"] = {},
    ["R"] = { alias_of = 'tr' },
    ["tr2"] = {},
    ["R2"] = { alias_of = 'tr2' },
    ["sensu"] = {},
    ["sensu2"] = {},
    ["codici"] = {},
    ["codici2"] = {},
    ["testu"] = {},
    ["testu2"] = {},
    ["aggittivu"] = {},
    ["lang"] = { checker = checkLang },
    ["lingua"] = { alias_of = 'lang' },
    ["lingua-link"] = { checker = checkLang },
    ["m"] = { type = m_params.BOOLEAN, default = false },
    ["nolink"] = { type = m_params.BOOLEAN, default = false },
    ["nocat"] = { type = m_params.BOOLEAN, default = false },
    ["ciavi"] = { default = mw.title.getCurrentTitle().text },
    ["nomu-cat"] = {},
    ["nomu-cat2"] = {},
  }
  local args = m_params.process(frame.args, params)
  local term = args["tèrmini"]
  local termPlural = args["tèrmini-plurali"] or (term .. "s")
  local caps = args["m"]
  local from = args["di"]
  local from2 = args["di2"]
  local transcription = args["tr"]
  local transcription2 = args["tr2"]
  local meaning = args["sensu"]
  local meaning2 = args["sensu2"]
  local codici = args["còdici"]
  local codici2 = args["còdici2"]
  local text = args["testu"] or from
  local text2 = args["testu2"] or from2
  local agg = args["aggittivu"]
  local noLink = args["nolink"]
  local noCategorization = args["nocat"]
  local lang = args["lang"]
  local linkLang = args["lang-link"] or (lang or "scn")
  local sortingKey = args["ciavi"]
  local category = args["nomu-cat"]
  local category2 = args["nomu-cat2"]
  local res = mw.ustring.format("[[%s#scn|%s]]", term, caps and m_basi.ucfirst(term) or term)
  if codici then
    linkLang = linkLang .. '-' .. codici
  end
  local format = function(baseWord, replacementText, baseString, additionalText, transcription, meaning)
    if baseWord then
      local word
      if noLink then
        word = baseWord
      else
        word = mw.ustring.format("[[%s#%s|%s]]", baseWord, linkLang, replacementText)
      end
      baseString = baseString .. mw.ustring.format(additionalText .. " de ''%s''", word)
    end
    if transcription then
      if baseString == '' then
        baseString = mw.ustring.format("''%s''", transcription)
      else
        baseString = mw.ustring.format("%s, ''%s''", baseString, transcription)
      end
    end
    if meaning then
      if baseString == '' then
        baseString = mw.ustring.format('("%s")', meaning)
      else
        baseString = mw.ustring.format('%s ("%s")', baseString, meaning)
      end
    end
    return baseString
  end
  local getCategory = function(cat_name)
    return m_basi.ucfirst(cat_name) .. " " ..
        (lang and "n " .. m_lingui.get_nom(lang) or "senza lingua nziruta")
  end
  res = format(from, text, res, agg and (" " .. agg) or "")
  res = format(from2, text2, res, " e", transcription, meaning)
  if noCategorization then
    return res
  else
    local categoryName
    if category then
      categoryName = category
    else
      if lang == nil then
        error("Còdici di lingua mancanti")
      end
      categoryName = getCategory(termPlural)
    end
    res = res .. m_basi.fa_catiguria_cuntinutu(categoryName, sortingKey)
    if category2 then
      if lang == nil then
        error("Còdici di lingua mancanti")
      end
      categoryName = getCategory(category2)
      res = res .. m_basi.fa_catiguria_cuntinutu(categoryName, sortingKey)
    end
    return res
  end
end
local LATIN_CODES = {
  'latinu vasciu',
  'gallu-rumanu',
  'latinu arcàicu',
  'latinu clàssicu',
  'latinu cuntimpuràniu',
  'latin ccrisiàsticu',
  'latin umanista',
  'latin mpiriali',
  'latin medievali',
  'latin pupulari',
  'latin tardu',
  'latin vulgari',
  'neulatinu',
}
local function getLanguageCode(langCode)
  return m_tabbella.contains(LATIN_CODES, langCode) and 'la' or langCode
end
local function checkLangExtended(langCode)
  return checkLang(getLanguageCode(langCode))
end
local function getLanguageName(langCode)
  return m_tabbella.contains(LATIN_CODES, langCode) and langCode or m_lingui.get_nom(langCode)
end
local function italicIfLatinScript(text)
  return m_Unicode_data.shouldItalicize(text) and mw.ustring.format("''%s''", text) or text
end
function p.templateEtyl(frame)
  local args = m_params.process(frame:getParent().args, {
    [1] = {},
    [2] = {},
    ['palora'] = {},
    [3] = { alias_of = 'mot' },
    ['tr'] = {},
    ['R'] = { alias_of = 'tr' },
    [4] = { alias_of = 'tr' },
    ['sensu'] = {},
    [5] = { alias_of = 'sensu' },
    ['dif'] = {},
    ['tipu'] = {},
    ['num'] = { type = m_params.INT, checker = function(n)
      return n > 0
    end },
    ['nocat'] = { type = m_params.BOOLEAN, default = false },
    ['link'] = { type = m_params.BOOLEAN, default = false },
  })
  local originLang = args[1]
  local destLang = args[2]
  local word = args['palora']
  local transcription = args['tr']
  local meaning = args['sensu']
  local alternativeText = args['dif']
  local anchorSection = args['tipu']
  local anchorNum = args['num']
  local noCat = args['nocat']
  local linkToLang = args['link']
  if not checkLangExtended(originLang) or (not noCat and not checkLangExtended(destLang)) then
    return '<span style="color:red">Erreuri template etil: lingua scanusciuta o assenti</span>' ..
        m_basi.fa_catiguria_cuntinutu('Wikizziunariu:Template etil senza lingua pricisata')
  end
  local categories = ''
  local content = ''
  local anchor = ''
  local originLangName = getLanguageName(originLang)
  local destLangName = getLanguageName(destLang)
  local displayedLang = linkToLang and m_basi.link_template(originLangName, 'scn') or originLangName
  content = ''
  if word then
    if anchorSection then
      anchor = anchorSection
    end
    if anchorNum then
      anchor = anchor .. '-' .. tostring(anchorNum)
    end
    content = italicIfLatinScript(m_basi.link_template(word, getLanguageCode(originLang), anchor, alternativeText, true))
  end
  if transcription then
    if content == '' then
      content = mw.ustring.format("''%s''", transcription)
    else
      content = mw.ustring.format("%s, ''%s''", content, transcription)
    end
  end
  if meaning then
    if content == '' then
      content = mw.ustring.format('("%s")', meaning)
    else
      content = mw.ustring.format('%s ("%s")', content, meaning)
    end
  end
  if content == '' then
    content = displayedLang
  else
    content = mw.ustring.format('%s %s', displayedLang, content)
  end
  if not noCat then
    if originLang == destLang then
      categories = categories .. m_basi.fa_catiguria_cuntinutu('Chiamati di template nun boni:etil')
    elseif originLang == 'unum' then
      categories = categories .. m_basi.fa_catiguria_cuntinutu(mw.ustring.format(
          'Palori n %s dirivati d’un’unumatupea',
          destLangName
      ))
    else
      categories = categories .. m_basi.fa_catiguria_cuntinutu(mw.ustring.format(
          'Palor n %s dirivati d’una palora n %s',
          destLangName,
          originLangName
      ))
    end
  end
  return content .. categories
end
function p.templateLienAncreEtym(frame)
  local wordTypes = mw.loadData("Mòdulu:tipi di palori/data")
  local args = m_params.process(frame:getParent().args, {
    [1] = { required = true, checker = checkLang },
    [2] = { required = true, checker = function(v)
      return wordTypes["alias"][v] ~= nil or wordTypes["testu"][v] ~= nil
    end },
    [3] = { type = m_params.INT, checker = function(v)
      return v > 0
    end },
    ["lucuzzioni"] = { type = m_params.BOOLEAN, default = false },
  })
  local langCode = args[1]
  local wordTypeData = wordTypes["testu"][wordTypes["alias"][args[2]] or args[2]]
  local locution = args["lucuzzioni"] and wordTypeData["lucuzzioni"] ~= nil
  local text = wordTypeData[locution and "lucuzzioni" or "mot"]
  local number = args[3]
  local anchor = langCode .. "-" .. wordTypeData["abbri"] .. (number ~= nil and ("-" .. tostring(number)) or "")
  text = m_basi.ucfirst(text)
  if number ~= nil then
    text = text .. " " .. tostring(number)
  end
  return mw.ustring.format("''([[#%s|%s]])''", anchor, text)
end
return p