Modül:GiftsByItem

Stardew Valley Wiki sitesinden
Margotbean (mesaj | katkılar) tarafından oluşturulmuş 23.33, 17 Ocak 2023 tarihli sürüm (wip)
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.


--[[This module currently takes a comma-separated list of villager names and
    transforms it into a bullet-separated list of links to villager pages.
    The next step is to pre-pend icons to the links.
    This will replace the arrays in Template:GiftsByItem
]]
local p = {}
local lang = string.upper(mw.getContentLanguage().code)	

--ts = translate & sort
function p.ts(frame)
    local villagerlist = frame.args[1]

    local villagertable = {}

    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(villagertable, v)
            end
        end
    end
  

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

	elseif lang == "TR" then
                    villagertable.insert(villagertable, "Cüce")
                    villagertable.remove(villagertable, "Dwarf")
            --for k,v in pairs(villagertable) do
                --if v == "Dwarf" then
                    --villagertable.insert(villagertable, "Cüce")
                    --villagertable.remove(villagertable, "Dwarf")
                    --v.gsub(v, "Dwarf", "Cüce")
                --end
                --if v == "Wizard" then
                    --v.gsub(v, "Wizard", "Büyücü")
                --end                  
            --end


            --villagerlist = villagerlist.gsub(villagerlist, "Dwarf", "Cüce")
            --villagerlist = villagerlist.gsub(villagerlist, "Wizard", "Büyücü")
	end



    table.sort(villagertable)



--mw.text.listToText(villagertable,  " • ")



    --put the table "villagertable" back into a string blob
    villagerlist = ""
    for i=1, (#villagertable-1) do
        villagerlist = villagerlist .. "[[" .. villagertable[i] .. "]]  • "
    end
    --We don't want a trailing bullet at the end of the list
    villagerlist = villagerlist .. "[[" .. villagertable[#villagertable] .. "]]"

    return villagerlist
end

return p