Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Lua banner/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ local yesno = require('Module:Yesno')
local mList = require('Module:List')
local mTableTools = require('Module:TableTools')
local mMessageBox = require('Module:Message box')
local TNT = require('Module:TNT')

local p = {}

local function format(msg)
return TNT.format('I18n/Lua banner', msg)
end

function p.main(frame)
local origArgs = frame:getParent().args
local args = {}
Expand All @@ -28,7 +33,7 @@ end
function p.renderBox(modules)
local boxArgs = {}
if #modules < 1 then
boxArgs.text = '<strong class="error">Error: no modules specified</strong>'
boxArgs.text = string.format('<strong class="error">%s</strong>', format('error_emptylist'))
else
local moduleLinks = {}
for i, module in ipairs(modules) do
Expand All @@ -44,9 +49,9 @@ function p.renderBox(modules)
title = title.basePageTitle
end
if title.contentModel == "Scribunto" then
boxArgs.text = 'This module depends on the following other modules:' .. moduleList
boxArgs.text = format('module-header') .. '\n' .. moduleList
else
boxArgs.text = 'This template uses [[BKDatabase:Lua|Lua]]:\n' .. moduleList
boxArgs.text = format('header') .. '\n' .. moduleList
end
end
boxArgs.type = 'notice'
Expand Down
234 changes: 234 additions & 0 deletions Other/Pinyin.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
local p = {}

local function remove_links_and_markup(text)
-- these either are unnecessary or interfere with assimilation

-- remove bold/italic
-- it is not impossible to allow bold/italic when it does not interfere with assimilation, but determining when to allow or disallow that adds complication for little practical gain
text = gsub(text, "'''", "")
text = gsub(text, "''", "")

-- remove HTML tags (except br)
text = gsub(text, "<[Bb][Rr] */?>", "&#10;")
text = gsub(text, "</?[A-Za-z][^>]->", "")
text = gsub(text, "&#10;", "<br>")

-- remove wikilinks
text = gsub(text, "%[%[[^%|]+%|(..-)%]%]", "%1")
text = gsub(gsub(text, "%[%[", ""), "%]%]", "")

text = mw.text.killMarkers(text)

return text
end

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

if a == "Ê" then
if n == 1 then return "E&#770;&#772;" end
if n == 2 then return "Ế" end
if n == 3 then return "E&#770;&#780;" end
if n == 4 then return "Ề" end
return a

end

if a == "ê" then
if n == 1 then return "e&#770;&#772;" end
if n == 2 then return "ế" end
if n == 3 then return "e&#770;&#780;" end
if n == 4 then return "ề" end
return a

end

if a == "N" then
if n == 2 then return "Ń" end
if n == 3 then return "Ň" end
if n == 4 then return "Ǹ" end
return a

end
if a == "n" then
if n == 2 then return "ń" end
if n == 3 then return "ň" end
if n == 4 then return "ǹ" end
return a
end

if a == "M" then
if n == 2 then return "Ḿ" end
if n == 4 then return "M&#x300;" end
return a
end
if a == "m" then
if n == 2 then return "ḿ" end
if n == 4 then return "m&#x300;" end
return a
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('^.*Ê') then
return chara:gsub("Ê", attachTone("Ê", n))
end
if chara:find('^.*ê') then
return chara:gsub("ê", attachTone("ê", 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

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

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

function p.pinyin(frame)
local input = frame.args[1]
if not input then
return
end
local ve = input:gsub("nue", "nve"):gsub("lue", "lve")
local out = ve:gsub("([%aüÊê]+)(%d)", selectVowel)
return (out:gsub("v", "ü"))
end


return p
15 changes: 15 additions & 0 deletions Testcases/Pinyin.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Click talk page to run tests.
local p = require('Module:UnitTests')

function p:test_pinyin()
self:preprocess_equals('{{#invoke:Pinyin|pinyin}}', '')
self:preprocess_equals('{{#invoke:Pinyin|pinyin|Wan4li2 Chang2cheng2}}', 'Wànlí Chángchéng')
self:preprocess_equals('{{#invoke:Pinyin|pinyin|She4 Diao1 yingxiongzhuan4}}', 'Shè Diāo yingxiongzhuàn')
self:preprocess_equals('{{#invoke:Pinyin|pinyin|Ai4 Dao3 Mo2 Shi4}}', 'Ài Dǎo Mó Shì')
self:preprocess_equals('{{#invoke:Pinyin|pinyin|Lü3 Bu4wei}}', 'Lǚ Bùwei')
self:preprocess_equals('{{#invoke:Pinyin|pinyin|Gong1lve4}}', 'Gōnglüè')
self:preprocess_equals('{{#invoke:Pinyin|pinyin|Xiu1ru3}}', 'Xiūrǔ')
self:preprocess_equals('{{#invoke:Pinyin|pinyin|M4 m2 ng2 N3 Ê2 ê3}}', 'M&#x300; ḿ ńg Ň Ế e&#770;&#780;')
end

return p
Loading