Jump to content

Module:Val/units

विकिपीडिया से
imported>The Mol Man (let's see if just convert works...) के द्वारा 00:00, 11 जनवरी 2015 के बदलाव
local units_tbl = mw.loadData('Module:Convert/data').all_units
function get_unit(_u)
	local c_unit = units_tbl[_u]
	if c_unit then
		if c_unit.target then
			c_unit = convert_data[c_unit.target]
		end
		return {abbr=c_unit.symbol or _u, link=c_unit.link or c_unit.name1 or _u, symlink=c_unit.symlink}
	else
		return {abbr=u, link=u}
	end
end

return function (u, tbl)
	if not tbl then
		tbl = {}
	end
	local per = tbl.per
	local link = tbl.link
	local perl = tbl.per_link

	local unit = get_unit(u)

	if link and unit.symlink then
		unit = unit.symlink
	elseif link then
		unit = '[['..unit.link..'|'..unit.abbr..']]'
	else
		unit = unit.abbr
	end
	if per then
		-- Look for "*" "." or "/"
		-- If found, add parentheses
		if u:find('[%*%.%/]') then
			unit = '('..unit..')'
		end
		local per_u = get_unit(per_u)
		if perl and per_u.symlink then
			per_u = per_u.symlink
		elseif perl then
			per_u = '[['..per_u..'|'..per_u.abbr..']]'
		else
			per_u = per_u.abbr
		end
		-- Look for "*" "." or "/"
		-- If found, add parentheses
		if per:find('[%*%.%/]') then
			per_u = '('..per_u..')'
		end
		unit = unit..'/'..per_u
	end

	if not unit.nospace then
		unit = ' '..unit
	end
	return unit
end