Jump to content

Module:Pinyin: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
No edit summary
Line 2: Line 2:


function attachTone(a, n)
function attachTone(a, n)
n = tonumber(n)
if a == "a" then
if a == "a" then
if n == 1 then return "ā" end
if n == 1 then return "ā" end
Line 89: Line 90:


function selectVowel(chara, n)
function selectVowel(chara, n)
if not chara then
return
end


if string.find(chara, "A", -1) then
if chara:find('^.*A') then
return chara:gsub("A", attachTone("A", n))
return chara:gsub("A", attachTone("A", n))
end
end
if string.find(chara, "a", -1) then
if chara:find('^.*a') then
return chara:gsub("a", attachTone("a", n))
return chara:gsub("a", attachTone("a", n))
end
end


if string.find(chara, "E", -1) then
if chara:find('^.*E') then
return chara:gsub("E", attachTone("E", n))
return chara:gsub("E", attachTone("E", n))
end
end
if string.find(chara, "e", -1) then
if chara:find('^.*e') then
return chara:gsub("e", attachTone("e", n))
return chara:gsub("e", attachTone("e", n))
end
end
if string.find(chara, "iu", -1) then
if chara:find('^.*iu') then
return chara:gsub("iu", "i"..attachTone("u", n))
return chara:gsub("iu", "i"..attachTone("u", n))
end
end
if string.find(chara, "i", -1) then
if chara:find('^.*i') then
return chara:gsub("e", attachTone("i", n))
return chara:gsub("i", attachTone("i", n))
end
end


if chara:find('^.*O') then
if string.find(chara, "O", -1) then
return chara:gsub("O", attachTone("O", n))
return chara:gsub("O", attachTone("O", n))
end
end
if string.find(chara, "o", -1) then
if chara:find('^.*o') then
return chara:gsub("o", attachTone("o", n))
return chara:gsub("o", attachTone("o", n))
end
end
if string.find(chara, "u", -1) then
if chara:find('^.*u') then
return chara:gsub("u", attachTone("u", n))
return chara:gsub("u", attachTone("u", n))
end
end
if string.find(chara, "v", -1) then
if chara:find('^.*v') then
return chara:gsub("v", attachTone("v", n))
return chara:gsub("v", attachTone("v", n))
end
end
if string.find(chara, "ü", -1) then
if chara:find('^.*ü') then
return chara:gsub("ü", attachTone("ü", n))
return chara:gsub("ü", attachTone("ü", n))
end
end
Line 133: Line 137:


function p.pinyin(frame)
function p.pinyin(frame)
return (string.gsub(frame.args[1], "(%a+)(%d)", selectVowel))
local out = (string.gsub(frame.args[1], "(%a+)(%d)", selectVowel))
return out:gsub("v", "ü")
end
end



Revision as of 14:19, 3 March 2014

local p = {}

function attachTone(a, n)
    n = tonumber(n)
	if a == "a" then
		if n == 1 then return "ā" end
		if n == 2 then return "á" end
		if n == 3 then return "ǎ" end
		if n == 4 then return "à" end
		return a
			
	end
	
	if a == "A" then
		if n == 1 then return "Ā" end
		if n == 2 then return "Á" end
		if n == 3 then return "Ǎ" end
		if n == 4 then return "À" end
		return a
			
	end
	
	if a == "e" then
		if n == 1 then return "ē" end
		if n == 2 then return "é" end
		if n == 3 then return "ě" end
		if n == 4 then return "è" end
		return a
			
	end
	
	if a == "E" then
		if n == 1 then return "Ē" end
		if n == 2 then return "É" end
		if n == 3 then return "Ě" end
		if n == 4 then return "È" end
		return a
			
	end
	
	if a == "i" then
		if n == 1 then return "ī" end
		if n == 2 then return "í" end
		if n == 3 then return "ǐ" end
		if n == 4 then return "ì" end
		return a
			
	end
	
	if a == "O" then
		if n == 1 then return "Ō" end
		if n == 2 then return "Ó" end
		if n == 3 then return "Ŏ" end
		if n == 4 then return "Ò" end
		return a
			
	end
	
	if a == "o" then
		if n == 1 then return "ō" end
		if n == 2 then return "ó" end
		if n == 3 then return "ǒ" end
		if n == 4 then return "ò" end
		return a
			
	end
	
	if a == "u" then
		if n == 1 then return "ū" end
		if n == 2 then return "ú" end
		if n == 3 then return "ǔ" end
		if n == 4 then return "ù" end
		return a
			
	end
	
	if (a == "v") or (a == "ü") then
		if n == 1 then return "ǖ" end
		if n == 2 then return "ǘ" end
		if n == 3 then return "ǚ" end
		if n == 4 then return "ǜ" end
		return "ü"
			
	end
	
	return a
	
end


function selectVowel(chara, n)
	
	if not chara then
		return
	end

	if chara:find('^.*A') then
		return chara:gsub("A", attachTone("A", n))
	end
	if chara:find('^.*a') then
		return chara:gsub("a", attachTone("a", n))
	end

	if chara:find('^.*E') then
		return chara:gsub("E", attachTone("E", n))
	end
	if chara:find('^.*e') then
		return chara:gsub("e", attachTone("e", n))
	end
	
	if chara:find('^.*iu') then
		return chara:gsub("iu", "i"..attachTone("u", n))
	end
	if chara:find('^.*i') then
		return chara:gsub("i", attachTone("i", n))
	end

	if chara:find('^.*O') then
		return chara:gsub("O", attachTone("O", n))
	end
	if chara:find('^.*o') then
		return chara:gsub("o", attachTone("o", n))
	end
	
	if chara:find('^.*u') then
		return chara:gsub("u", attachTone("u", n))
	end
	
	if chara:find('^.*v') then
		return chara:gsub("v", attachTone("v", n))
	end
	if chara:find('^.*ü') then
		return chara:gsub("ü", attachTone("ü", n))
	end

end

function p.pinyin(frame)
	local out = (string.gsub(frame.args[1], "(%a+)(%d)", selectVowel))
	return out:gsub("v", "ü")
end

 
return p