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 15:29, 11 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",
}

local function tCase(first, rest)
   return first:upper()..rest:lower()
end

function p.Kxr(frame)
	-- simplify handling of args
	local getArgs = require('Module:Arguments').getArgs
	local args = getArgs(frame)
	local r = math.floor(tonumber(args[1]))
	if args[2] then
		error("Only one argument of a number between 1 and 214 is accepted")
	elseif r < 1 or r > 214 then
		error("Argument must be between 1 and 214")
	else
		return p._Kxr(r)
	end
	return
end

function p._Kxr(r)
	local unicode = 0x2F00 + r - 1
	local u_str   = "&#" .. unicode .. ";"
	local result  = u_str .. " <span style=\"font-variant: small-caps;\">" .. labels[r]:gsub("(%a)([%w_']*)", tCase) .. "</span>"

	return result
end

return p