Modulo:mli6393wpsil

El Vikivortaro
 MODULO
Memtesto ne disponeblas.

--[===[

MODULE "MLI6393WPSIL" (ligilo 639-3 wikipedia sil)

"eo.wiktionary.org/wiki/Modulo:mli6393wpsil" <!--2020-Nov-17-->

Purpose: creates 5 links (4 to wikipedia, 1 to SIL) from
         a 3-letter ISO 639-3:2007 language code

Utilo: kreas 5 ligilojn (4 al vikipedio, 1 al SIL) el
       3-litera ISO 639-3:2007 lingvokodo

Manfaat: membuat 5 pranala (4 ke wikipedia, 1 ke SIL) dari
         kode bahasa berhuruf 3 menurut ISO 639-3:2007

Syfte: skapar 5 laenkar ...

Used by templates / Uzata far sxablonoj:
- only "ligilo-639-3-wp-sil" (not to be called from any other place)

Required submodules / Bezonataj submoduloj:
- none / neniuj

This module can accept parameters whether sent to itself (own frame) or
to the caller (caller's frame). If there is a parameter "caller=true"
on the own frame then that own frame is discarded in favor of the
caller's one.

Parameters: - 1 anonymous obligatory parameter
              - ISO 639-3:2007 language code or "---" if none
            - 1 named optional parameter
              - "nocat" (value "true" to suppress categorization on error,
                anything else is ignored)

Returned: - one string with 1 line with 5 or exceptionally only 2 links,
            or whining string and 2 tracking categories on error

On error the nasty message
is "Erara uzo de sxablono {{ligilo-639-3-wp-sil}}. Nepre havigu
validan triliteran ISO 639-3:2007 kodon." with "{{ligilo-639-3-wp-sil}}"
being a link to the template. The tracking categories are
[[Kategorio:Erara uzo de sxablono]] and
[[Kategorio:Erara uzo de sxablono (ligilo-639-3-wp-sil)]].

Note that we construct the link with just "<code>{{[[" ...
"]]}}</code>", NOT with "<code><nowiki>{{</nowiki>[[" ...
"]]<nowiki>}}</nowiki></code>", since string coming from a module is
subject to reduced parsing only, thus wiki links and external http links
and "<code>" still do work whereas template calls and "<nowiki>" do NOT.

]===]

local li6393wpsil = {}

------------------------------------------------------------------------

---- CONSTANTS ----

------------------------------------------------------------------------

  -- constant strings (generic & misc)

  local constrkros  = '&nbsp;#&nbsp;#&nbsp;'       -- lagom -> huge circumfix
  local constrelabg = '<span class="error"><b>'    -- lagom whining begin
  local constrelaen = '</b></span>'                -- lagom whining end

  -- constant strings EO (not needed for ID)

  local constrsxupc = string.char(0xC5,0x9C)   -- uppercase EO "SX"
  local constrsxlwc = string.char(0xC5,0x9D)   -- lowercase EO "sx"

  -- constant strings EO (no ID yet) -- error

  local constrkatp = 'Kategorio:'              -- EO namespace prefix
  local constrtplp = constrsxupc .. 'ablono:'  -- EO "SXablono:" namespace prefix

  local constrkoll = 'ligilo-639-3-wp-sil'     -- name of the caller (hardcoded, we do NOT peek it)

  local constrwhi3 = 'Erara uzo de ' .. constrsxlwc .. 'ablono'              -- note the leading uppercase but no trailing dot nor space
  local constrwhi4 = 'Nepre havigu validan triliteran ISO 639-3:2007 kodon'  -- note the leading uppercase but no trailing dot nor space

  -- constant strings EO (no ID yet) -- success -- the 5 links

  local constrf30 = ' -- '                                  -- separator, note the two spaces
  local constrf31 = '-wp&nbsp;pri&nbsp;"'                   -- note the trailing quot
  local constrf32 = '"&nbsp;(<small>tabelo</small>&nbsp;"'  -- note both quotes and the unbalanced "("
  local constrf33 = '")]]'                                  -- note the leading quot and the 3 unbalanced brackets ")" and "]]"

  local constrf40 = '[[w:ISO_639-3|ISO&nbsp;639-3&nbsp;kodo]]&nbsp;=&nbsp;<b>"'  -- note the trailing quot
  local constrf41 = '"</b>'                                                      -- note the leading quot

  local constrf50 = '[[w:ISO_639-3_'   -- note the unbalanced "[[" and the trailing underscore
  local constrf51 = '|eo'              -- note the leading wall

  local constrf60 = '[[w:en:ISO_639:'  -- note the unbalanced "[[" and the trailing colon
  local constrf61 = '|en'              -- note the leading wall

  local constrf70 = '[https://iso639-3.sil.org/code/'  -- note the unbalanced single "["
  local constrf71 = ' SIL&nbsp;pri&nbsp;"'             -- note the leading space and trailing quot
  local constrf72 = '"]'                               -- note the leading quot and the unbalanced single "]"

  local constrf80 = '([[w:Listo de lingvoj de la mondo|eo-wp&nbsp;<small>listoj&nbsp;kun&nbsp;lingvoj</small>]])'

  local constrf90 = '(<small>ne ekzistas</small>)'

------------------------------------------------------------------------

---- MAIN EXPORTED FUNCTION ----

------------------------------------------------------------------------

function li6393wpsil.ek (arxframent)

  -- general unknown type

  local vartmp = 0     -- variable without type

  -- special type "args" AKA "arx"

  local arxsomons = 0  -- metaized "args" from our own or caller's "frame"

  -- general "str"

  local strkod    = ""  -- 3 lowercase letters or "---"
  local strbeg    = ""  -- 1 lowercase letter
  local strtmp    = ""
  local strtpm    = ""
  local strret    = ""  -- output string

  -- general "num"

  local numlong   = 0  -- length of parameter
  local numb3x    = 0
  local numb4x    = 0
  local numb5x    = 0

  -- general "boo"

  local booerr    = false  -- fatal error flag
  local boonokod  = false  -- true for "---"
  local boonocat  = false

  ---- GET THE ARX (ONE OF TWO) ----

  arxsomons = arxframent.args -- "args" from our own "frame"
  vartmp = arxsomons ["caller"]
  if (vartmp=="true") then
    arxsomons = arxframent:getParent().args -- "args" from caller's "frame"
  end--if

  ---- SEIZE 1 OBLIGATORY ANONYMOUS PARAMETER ----

  vartmp = arxsomons[1] -- can be "nil"
  if (type(vartmp)=="string") then
    numlong = string.len (vartmp)
    if (numlong==3) then -- 3 octet:s
      strkod = vartmp -- otherwise it will remain empty
    end--if
  end--if

  ---- SEIZE 1 OPTIONAL NAMED PARAMETER ----

  vartmp = arxsomons["nocat"] -- can be "nil"
  if (type(vartmp)=="string") then
    if (vartmp=="true") then
      boonocat = true
    end--if
  end--if

  ---- CHECK THE CODE AND SEPARATE THE BEGINNING LETTER ----

  if (strkod=="") then
    booerr = true
  else
    if (strkod=="---") then
      boonokod  = true
    else
      numb3x = string.byte (strkod,1,1)
      numb4x = string.byte (strkod,2,2)
      numb5x = string.byte (strkod,3,3)
      if ((numb3x<97) or (numb3x>122) or(numb4x<97) or (numb4x>122) or(numb5x<97) or (numb5x>122)) then
        booerr = true
      else
        strbeg = string.char(numb3x)
      end--if
    end--if (strkod=="---") else
  end--if

  ---- CARRY OUT THE HARD WORK -- SUCCESS ----

  if (booerr==false) then

    strret = constrf40 .. strkod .. constrf41 .. constrf30

    if (boonokod) then
      strret = strret .. constrf90 -- "---" -> only 2 links and "ne ekzistas"
    else
      strret = strret .. constrf50 .. strbeg .. constrf51 .. constrf31 .. strkod .. constrf32 .. strbeg .. constrf33
      strret = strret .. constrf30
      strret = strret .. constrf60 .. strbeg .. constrf61 .. constrf31 .. strkod .. constrf32 .. strbeg .. constrf33
      strret = strret .. constrf30
      strret = strret .. constrf70 .. strkod .. constrf71 .. strkod .. constrf72
    end--if

    strret = strret .. constrf30 .. constrf80

  end--if

  ---- CARRY OUT THE HARD WORK -- ERROR ----

  if (booerr) then

    -- brew 2 separate red bold parts

    strtmp = constrelabg .. constrwhi3 .. constrelaen -- before li
    strtpm = constrelabg .. ". " .. constrwhi4 .. "." .. constrelaen -- after li

    -- brew the complaint with link in the middle, no "nowiki" here

    strret = constrkros .. strtmp .. " <code>{{[["
    strret = strret .. constrtplp .. constrkoll .. "|" .. constrkoll
    strret = strret .. "]]}}</code>" .. strtpm .. constrkros

    -- brew 2 cat:s

    if (boonocat==false) then

      strret = strret .. "[[" .. constrkatp .. constrwhi3 .. " ("
      strret = strret .. constrkoll .. ")]]"

      strret = strret .. "[[" .. constrkatp .. constrwhi3 .. "]]"

    end--if

  end--if

  ---- RETURN THE JUNK STRING ----

  return strret -- can be empty

end--function

  ---- RETURN THE JUNK LUA TABLE ----

return li6393wpsil