Modul:Sandkasse/Dipsacus fullonum/Modul:Sandkasse

Fra Wikipedia, den frie encyklopædi
Documentation icon Moduldokumentation[opret]
require('Modul:No globals')
local p = {}

function p.entry(frame)
	local module = mw.title.new('Cycling race', 'Module') 
	local source = module:getContent()

	local startpos, endpos = 1
	repeat
		startpos, endpos = string.find(source, '\n%s*local%s+l10nDef%s*=%s*{', startpos)
		if startpos then
			local defs = {}
			local p1, p2, key, value = endpos + 1
			local last = endpos + 1
			local count = 0
			repeat
				p1, p2, key, value = string.find(source, '^%s*(%b[])%s*=%s*(%b{}%s*,?)', p1)

mw.logObject(p1)
mw.logObject(p2)
mw.logObject(key)
mw.logObject(value)

				if p1 then
					defs[key] = value
					p1 = p2 + 1
					last = p1
				end
				count = count + 1
			until p1 == nil
			local wanted = defs['["da"]'] or defs['["en"]']

mw.logObject(count)
mw.logObject(wanted)

			if wanted then
				source = string.sub(source, 1, endpos) .. ' ["da"] = ' .. wanted .. string.sub(source, last)
			else
				source = string.sub(source, 1, endpos) ..  string.sub(source, last)
			end
			
			startpos = endpos + 1
		end
	until startpos == nil

	local output = frame:extensionTag{ name = 'pre', content = source, args = {} }
	return output
end

return p