Jump to content

Module:Sandbox/ATDT

From Wikipedia, the free encyclopedia
local function is_identity_map(t)
	for k, v in pairs(t) do
		if k ~= v then return false end
	end
	return true
end

-- 2. The Logic Simulation
local function parse(k, local_digits)
	-- "skip_digit_translate" logic
	if not is_identity_map(local_digits) and type(k) == 'string' then
		-- If we didn't skip, run gsub and prove it
		return mw.ustring.gsub(k, '%d', local_digits) .. " [Ran gsub]"
	end
	-- If we skipped, return original
	return k .. " [Skipped gsub]"
end

-- 3. The Proof
local en_digits = {['0']='0', ['1']='1'} 
local bn_digits = {['০']='0', ['১']='1'} -- Bengali

return table.concat({
	"Enwiki (Volume 1): " .. parse("Volume 1", en_digits),
	"Bengali (Volume ১): " .. parse("Volume ১", bn_digits)
}, "\n")