မာတိကာသို့ ခုန်သွားရန်

မဝ်ဂျူ:also/auto

နူ ဝိက်ရှေန်နရဳ
ထာမ်ပလိက်တဏအ်ဒးနွံကဵုလိက်စၟတ်သမ္တီမချူလဝ်သာဓက။
သ္ပဂုန်တုဲထာမ်ပလိက်တဏအ်ဒးစၟတ်သမ္တီကဵုလိက်မချူလဝ်နူကဵုဓမံက်ထ္ၜးကဵုဗီုပြၚ်ကိစ္စမရန်တၟအ်လဝ် ကဵု ပရေၚ်မရပ်စပ်လ္တူမုက်လိက်နကဵုလိက်စၟတ်သမ္တီမချူလဝ်သာဓက

local p = {}

local PAGENAME = mw.title.getCurrentTitle().text
local m_unicode = require("Module:Unicode data")
local m_customkeys = require("Module:also/customkeys")

function get_hashkey_metakey(word, custom_hashkey)
	local buffer = word

	-- impossible to convert kanji to hiragana here
	if mw.ustring.find(buffer, "[ァ-ヿ]") then
		buffer = require("Module:ja").kata_to_hira(buffer)
	end
	buffer = mw.ustring.toNFKD(mw.ustring.lower(buffer))
	for k, v in pairs(m_customkeys) do
		buffer = mw.ustring.gsub(buffer, k, v)
	end

	local hashkey
	if custom_hashkey then
		hashkey = custom_hashkey
	else
		local hashkey_obj = {}
		for cp in mw.ustring.gcodepoint(buffer) do
			table.insert(hashkey_obj, is_valid(cp) and mw.ustring.char(cp) or "")
		end
		hashkey = table.concat(hashkey_obj)
	end

	local metakey = mw.ustring.match(hashkey, "^[a-z]")
	if not metakey then
		if mw.ustring.find(hashkey, "^[α-ω]") then
			metakey = "Grek"
		elseif mw.ustring.find(hashkey, "^[ऄ-ॿ]") then
			metakey = "Deva"
		elseif mw.ustring.find(hashkey, "^[က-႟]") then
			metakey = "Mymr"
		elseif mw.ustring.find(hashkey, "^[ก-๛]") then
			metakey = "Thai"
		elseif mw.ustring.find(hashkey, "^[ກ-ໟ]") then
			metakey = "Laoo"
		elseif mw.ustring.find(hashkey, "[ぁ-ヿ]") then -- also kanji word that has kana
			metakey = "Kana"
		elseif mw.ustring.find(hashkey, "^[㐀-䶿一-鿿豈-龎]") then
        	metakey = "Hani"
		else
			metakey = "else"
		end
	end
	return hashkey, metakey
end

function is_valid(cp)
	local category = m_unicode.lookup_category(cp)
	return (category:match("^[LN].$") or category == "Mc" or category == "Sc") -- can't rely on built-in %w class
end

function p.main(frame)
	local hashkey, metakey = get_hashkey_metakey(PAGENAME, frame:getParent().args["key"])
	local data = require("Module:also/lookups/" .. metakey)[hashkey] or {} -- data are in a-z and nonLatin submodules
	for i, v in ipairs(frame:getParent().args) do -- if it has manual params
		table.insert(data, v)
	end

	if #data == 0 then
		error("The word “" .. PAGENAME .. "” is not contained in the key “" .. hashkey .. "” and no more word is given. Or a customized 'key=' can be added.")
	end

	local new_frame = frame:newChild{title = frame:getTitle(), args = data}
	function new_frame:getParent()
		return self
	end
	return require('Module:also').main(new_frame)
end

return p