ข้ามไปเนื้อหา

มอดูล:udi-entryname

จาก วิกิพจนานุกรม พจนานุกรมเสรี

local export = {}
local u = mw.ustring.char

local tt = {
	[u(0x0300)] = "", [u(0x0301)] = "", [u(0x0304)] = ""
}

local cyrillic = {
	["I"] = "ӏ", ["l"] = "ӏ", ["І"] = "ӏ", ["Ӏ"] = "ӏ", ["ᴴ"] = "ᵸ"
}

function export.makeEntryName(text, lang)
	local str_gsub = string.gsub
	local UTF8_char = "[%z\1-\127\194-\244][\128-\191]*"
	lang = require("Module:languages").getByCode(lang)
	
	local script = require("Module:scripts").findBestScript(text, lang):getCode()
	if script == "Cyrl" then -- if script is Cyrillic, correct "false" palochkas and dialectal nasal ᵸ written as Latin ᴴ; not desirable if using another script
		for character, replacement in pairs(cyrillic) do
			text = str_gsub(text, character, replacement)
		end
	end
	
	return str_gsub(mw.ustring.toNFD(text), UTF8_char, tt)
end

return export