-- Übersetzt "alte" Bezeichnungen der Bücher der Bibel in "neue"
-- Bezeichnungen für www.die-bibel.de

local export = {}

function export.params (frame)

  if not (frame.args[1] and frame.args[1] ~= "") then
    return "Parameter 1 Buchname fehlt"
  end
  local buch = frame.args[1]

  local kapitel = ""
  if frame.args[2] and frame.args[2] ~= "" then
    kapitel = frame.args[2]
  end

  local vers = ""	
  if frame.args[3] and frame.args[3] ~= "" then
    vers = frame.args[3]
  end


  local lu2online = {
    ["Am"] = "AMO",
    ["Apg"] = "ACT",
    ["Apk"] = "REV",
    ["Bar"] = "BAR",
    ["Bar 6"] = "BAR.6",
    ["BrJer"] = "BAR.6",
    ["1. Chr"] = "1CH",
    ["2. Chr"] = "2CH",
    ["Dan"] = "DAN",
    ["DanZ"] = "DAG",
    ["Dtn"] = "DEU",
    ["Eph"] = "EPH",
    ["EpJer"] = "BAR.6",
    ["Esra"] = "EZR",
    ["Est"] = "EST",
    ["EstG"] = "ESG",
    ["EstZ"] = "ESG",
    ["Ex"] = "GEN",
    ["Ez"] = "EZK",
    ["Gal"] = "GAL",
    ["Geb.Man"] = "MAN",
    ["Gen"] = "GEN",
    ["Hab"] = "HAB",
    ["Hag"] = "HAG",
    ["Hebr"] = "HEB",
    ["Hes"] = "EZK",
    ["Hiob"] = "JOB",
    ["Hld"] = "SNG",
    ["Hos"] = "HOS",
    ["Ijob"] = "JOB",
    ["Jak"] = "JAS",
    ["Jdt"] = "JDT",
    ["Jer"] = "JER",
    ["Jes"] = "ISA",
    ["Joel"] = "JOL",
    ["Joh"] = "JHN",
    ["1. Joh"] = "1JN",
    ["2. Joh"] = "2JN",
    ["3. Joh"] = "3JN",
    ["Jona"] = "JON",
    ["Jos"] = "JOS",
    ["Jud"] = "JUD",
    ["Klgl"] = "LAM",
    ["Koh"] = "ECC",
    ["Kol"] = "COL",
    ["1. Kön"] = "1KI",
    ["2. Kön"] = "2KI",
    ["1. Kor"] = "1CO",
    ["2. Kor"] = "2CO",
    ["Lev"] = "NUM",
    ["Lk"] = "LUK",
    ["1. Makk"] = "1MA",
    ["2. Makk"] = "2MA",
    ["Mal"] = "MAL",
    ["Mi"] = "MIC",
    ["Mk"] = "MRK",
    ["1. Mose"] = "GEN",
    ["2. Mose"] = "EXO",
    ["3. Mose"] = "LEV",
    ["4. Mose"] = "NUM",
    ["5. Mose"] = "DEU",
    ["Mt"] = "MAT",
    ["Nah"] = "NAM",
    ["Neh"] = "NEH",
    ["Num"] = "NUM",
    ["Obd"] = "OBA",
    ["Offb"] = "REV",
    ["1. Petr"] = "1PE",
    ["2. Petr"] = "2PE",
    ["Phil"] = "PHP",
    ["Phlm"] = "PHM",
    ["Pred"] = "ECC",
    ["Ps"] = "PSA",
    ["Ri"] = "JDG",
    ["Röm"] = "ROM",
    ["Rut"] = "RUT",
    ["Sach"] = "ZEC",
    ["1. Sam"] = "1SA",
    ["2. Sam"] = "2SA",
    ["Sir"] = "SIR",
    ["Spr"] = "PRO",
    ["St zu Dan"] = "DAG",
    ["St zu Est"] = "ESG",
    ["1. Thess"] = "1TH",
    ["2. Thess"] = "2TH",
    ["1. Tim"] = "1TI",
    ["2. Tim"] = "2TI",
    ["Tit"] = "TIT",
    ["Tob"] = "TOB",
    ["Weish"] = "WIS",
    ["Zef"] = "ZEP",

    ["1 Chr"] = "1CH",
    ["2 Chr"] = "2CH",
    ["1 Joh"] = "1JN",
    ["2 Joh"] = "2JN",
    ["3 Joh"] = "3JN",
    ["1 Kön"] = "1KI",
    ["2 Kön"] = "2KI",
    ["1 Kor"] = "1CO",
    ["2 Kor"] = "2CO",
    ["1 Makk"] = "1MA",
    ["2 Makk"] = "2MA",
    ["1 Mos"] = "GEN",
    ["2 Mos"] = "EXO",
    ["3 Mos"] = "LEV",
    ["4 Mos"] = "NUM",
    ["5 Mos"] = "DEU",
    ["1 Petr"] = "1PE",
    ["2 Petr"] = "2PE",
    ["1 Sam"] = "1SA",
    ["2 Sam"] = "2SA",
    ["1 Thess"] = "1TH",
    ["2 Thess"] = "2TH",
    ["1 Tim"] = "1TI",
    ["2 Tim"] = "2TI"

  }

  local mapbuch = lu2online[buch]

  if mapbuch == nil then
    mapbuch = buch
  end

  -- ist ein Versbereich angegeben?
  -- Halbgeviertstrich?
  vers = mw.ustring.gsub( vers, '–', '-' )
  local pos,_ = mw.ustring.find(vers,"-",1,true)
  if pos ~= nil then
    if pos == 1 then
      vers = "1" .. vers
      pos = pos + 1
    end
    local tail = mw.ustring.sub(vers,pos + 1)
    vers = mw.ustring.sub(vers,1,pos - 1)
    if tail ~= "" then
      vers = vers .. "-" .. mapbuch .. "." .. kapitel .. "." .. tail
    end
  end

  if vers ~= "" then
    vers = "." .. vers
  end

  return mapbuch .. "." .. kapitel .. vers


end


return export