Jump to content

Module:Kangxi radical

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Remsense (talk | contribs) at 03:50, 12 October 2023. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

require('strict')

local p = {}
	
local labels = { -- ten per line
	"one", "line", "dot", "slash", "second", "hook", "two", "lid", "man", "legs",
	"enter", "eight", "down box", "cover", "ice", "table", "open box", "knife", "power", "wrap",
	"spoon", "right open box", "hiding enclosure", "ten", "divination", "seal", "cliff", "private", "again", "mouth",
	"enclosure", "earth", "scholar", "go", "go slowly", "evening", "big", "woman", "child", "roof",
	"inch", "small", "lame", "corpse", "sprout", "mountain", "river", "work", "oneself", "turban",
	"dry", "short thread", "dotted cliff", "long stride", "two hands", "shoot", "bow", "snout", "bristle", "step",
	"heart", "halberd", "door", "hand", "branch", "rap", "script", "dipper", "axe", "square",
	"not", "sun", "say", "moon", "tree", "lack", "stop", "death", "weapon", "do not",
	"compare", "fur", "clan", "steam", "water", "fire", "claw", "father", "double x", "half tree trunk",
	"slice", "fang", "cow", "dog", "profound", "jade", "melon", "tile", "sweet", "life",
	"use", "field", "bolt of cloth", "sickness", "dotted tent", "white", "skin", "dish", "eye", "spear",
	"arrow", "stone", "spirit", "track", "grain", "cave", "stand", "bamboo", "rice", "silk",
	"jar", "net", "sheep", "feather", "old", "and", "plow", "ear", "brush", "meat",
	"minister", "self", "arrive", "mortar", "tongue", "oppose", "boat", "stopping", "color", "grass",
	"tiger", "insect", "blood", "walk enclosure", "clothes", "west", "see", "horn", "speech", "valley",
	"bean", "pig", "badger", "shell", "red", "run", "foot", "body", "cart", "bitter",
	"morning", "walk", "city", "wine", "distinguish", "village", "gold", "long", "gate", "mound",
	"slave", "short tailed bird", "rain", "blue", "wrong", "face", "leather", "tanned leather", "leek", "sound",
	"leaf", "wind", "fly", "eat", "head", "fragrant", "horse", "bone", "tall", "hair", 
	"fight", "sacrificial wine", "cauldron", "ghost", "fish", "bird", "salt", "deer", "wheat", "hemp",
	"yellow", "millet", "black", "embroidery", "frog", "tripod", "drum", "rat", "nose", "even",
	"tooth", "dragon", "turtle", "flute",
}

function p.Kxr(frame)
	local getArgs = require('Module:Arguments').getArgs
	return p._Kxr(getArgs(frame))
end

function p.uStr(hex)
	return	"&#" .. hex .. ";"
end

function p._Kxr(args)
	local num = nil
	if tonumber(args[1]) then
		local num = math.floor(tonumber(args[1]))
	end
	local link = false
	
	if args["l"] or args["link"] or args["links"] then
		link = true
	end
	
	if num < 1 or num > 214 then
		error("Argument must be between 1 and 214")
	end
	
	local unicode = 0x2F00 + num - 1
	local label_style = "\"font-variant: small-caps;font-size:smaller;font-weight:bolder\""
	
	local label = string.upper(labels[num])
	if link then
		label = "[[Radical " .. num .. "|".. label .. "]]"
	end
	label = "<span style=" .. label_style ..  ">" ..  label .. "</span>"
	local result  = "<span lang=\"und-Hani\">" .. uStr(unicode) .. "</span>&emsp13;".. label
	mw.log(result)
	return result
end

return p