Modül:GiftsByItem

Stardew Valley Wiki sitesinden
Margotbean (mesaj | katkılar) tarafından oluşturulmuş 22.32, 17 Ocak 2023 tarihli sürüm
Gezinti kısmına atla Arama kısmına atla

Description

This module takes a comma-separated list of villager names and transforms it into a bullet-separated list of villager icons + links to villager pages.

This module performs tasks that were formerly performed by arrays (sorting, translating, and formatting) in Template:GiftsByItem.

This module can be copy/pasted into all languages without alteration.

Please report any problems or issues with the module on the discussion page for Template:GiftsByItem.


local p = {}

function p.ts(frame)
        local villagerlist = frame.args[1]
        local lang = string.upper(mw.getContentLanguage().code)	

	if lang == "DE" then
            villagerlist = villagerlist.gsub(villagerlist, "Wizard", "Zauberer")
            villagerlist = villagerlist.gsub(villagerlist, "Dwarf", "Zwerg")

	elseif lang == "TR" then
            villagerlist = villagerlist.gsub(villagerlist, "Dwarf", "Cüce")
            villagerlist = villagerlist.gsub(villagerlist, "Wizard", "Büyücü")
	end


  local result = {}

  if villagerlist ~= nil then
    local values = mw.text.split(villagerlist, ",", true)
    for i = 1, #values do
      v = mw.text.trim(values[i])
      if v ~= "" then
        table.insert(result, v)
      end
    end
  end
  
  table.sort(result)
  --put the table "result" back into a string blob
  villagerlist = ""
  for i=1, (#result-1) do
    villagerlist = villagerlist .. result[i] .. " • "
  end
  villagerlist = villagerlist .. result[#result]


        --villagerlist = villagerlist.gsub(villagerlist, "," , " • ")
        --villagerlist = mw.text.truncate(villagerlist, (#villagerlist - 3))
  return villagerlist
end

return p