La documentation pour ce module peut être créée à Module:bac à sable/Assassas77/Documentation
local export = {}
local find = mw.ustring.find
local gsub = mw.ustring.gsub
local len = mw.ustring.len
local match = mw.ustring.match
local sub = mw.ustring.sub
local split = mw.text.split
local upper = mw.ustring.upper
local m_zh = require("Module:bac à sable/Assassas77-2")
local _m_zh_data = nil
-- local hom_data = mw.loadData("Module:bac à sable/Assassas77-2/data/cmn-hom")
-- if not empty
local function ine(var)
if var == "" then
return nil
else
return var
end
end
local breve, hacek = mw.ustring.char(0x306), mw.ustring.char(0x30C)
local decompose = mw.ustring.toNFD
local function breve_error(text)
if type(text) ~= "string" then
return
end
text = decompose(text)
if text:find(breve) then
error('The pinyin text "' .. text .. '" contains a breve. Replace it with "' .. text:gsub(breve, hacek) .. '".', 2)
end
end
local function m_zh_data()
if _m_zh_data == nil then _m_zh_data = mw.loadData("Module:zh/data/cmn-tag") end;
return _m_zh_data;
end
local py_detone = {
= 'a', = 'a', = 'a', = 'a',
= 'o', = 'o', = 'o', = 'o',
= 'e', = 'e', = 'e', = 'e',
= 'ê', = 'ê', = 'ê', = 'ê',
= 'i', = 'i', = 'i', = 'i',
= 'u', = 'u', = 'u', = 'u',
= 'ü', = 'ü', = 'ü', = 'ü',
= 'm', = 'm', = 'm', = 'm',
= 'n', = 'n', = 'n', = 'n',
}
local py_tone = {
= '1',
= '2',
= '3',
= '4'
}
function export.py_transform(text, detone, not_spaced)
if type(text) == 'table' then text, detone, not_spaced = text.args, text.args, text.args end
if find(text, '') then
error("Pinyin contains the hidden character: (U+200B). Please remove that character from the text.")
end
detone = ine(detone)
not_spaced = ine(not_spaced)
text = gsub(gsub(mw.ustring.toNFD(text), mw.ustring.toNFD('ê'), 'ê'), mw.ustring.toNFD('ü'), 'ü')
local tones = ''
if find(mw.ustring.lower(text), '' .. tones .. '?' .. tones .. '') and not not_spaced then
error(("Missing apostrophe before null-initial syllable - should be \"%s\" instead."):format(gsub(text, '(' .. tones .. '?)(' .. tones .. ')', "%1'%2"))) end
text = mw.ustring.lower(text)
if not mw.ustring.find(text, tones) and text:find('') then
return gsub(text, '(%d)(%l)', '%1 %2')
end
if find(text, '') then
text = gsub(text, '()$', { = ' yī', = ' bù'})
text = gsub(text, '()', ' %1 ')
text = gsub(text, '()', ' %1 ')
text = gsub(text, ' +', ' ')
text = gsub(text, '^ ', '')
text = gsub(text, ' $', '')
text = gsub(text, '%. %. %.', '...')
end
text = gsub(text, "", ' ')
text = gsub(text, '(' .. tones .. '?n?g?r?)(h?)', '%1 %2')
text = gsub(text, ' ()$', '%1')
text = gsub(text, ' () ', '%1 ')
if detone then
text = mw.ustring.gsub(text, tones, py_tone)
text = gsub(text, '()(*)', '%2%1')
text = mw.ustring.gsub(text, '() ', '%15 ')
text = mw.ustring.gsub(text, '()$', '%15')
end
if not_spaced then
text = gsub(text, ' ', '')
end
return mw.ustring.toNFC(text)
end
function export.py_ipa(text)
local ipa_initial = {
= 'p', = 'pʰ', = 'm', = 'f',
= 't', = 'tʰ', = 'n', = 'l',
= 'k', = 'kʰ', = 'x', = 'ŋ',
= 't͡ɕ', = 't͡ɕʰ', = 'ɕ',
= 't͡s', = 't͡sʰ', = 's', = 'ʐ',
= 'ʈ͡ʂ', = 'ʈ͡ʂʰ', = 'ʂ',
= ''
}
local ipa_initial_tl = {
= 'b̥', = 'd̥', = 'g̊', = 'd͡ʑ̥', = 'd͡z̥', = 'ɖ͡ʐ̥'
}
local ipa_final = {
= 'ɥɑɻ', = 'jɑ̃ɻ', = 'jɑ̃ɻ', = 'wɑ̃ɻ', = 'wɑ̃ɻ', = 'jɤ̃ɻ', = 'ʊ̃ɻ', = 'jʊ̃ɻ', = 'jʊ̃ɻ',
= 'y̯ɛn', = 'i̯ɑŋ', = 'i̯ɑŋ', = 'u̯ɑŋ', = 'u̯ɑŋ', = 'iŋ', = 'u̯əŋ', = 'i̯ʊŋ', = 'i̯ʊŋ', = 'jɑɻ', = 'jɑɻ', = 'wɑɻ', = 'wɑɻ', = 'wɑɻ', = 'wɑɻ', = 'jaʊɻʷ', = 'jaʊɻʷ', = 'ɥɑɻ', = 'ɥɑɻ', = 'ɑ̃ɻ', = 'ɥɛɻ', = 'wəɻ', = 'wəɻ', = 'jɤʊɻʷ', = 'jəɻ', = 'ɥəɻ', = 'ɤ̃ɻ', = 'jɤ̃ɻ', = 'ʊ̃ɻ',
= 'u̯aɪ̯', = 'u̯aɪ̯', = 'i̯aɪ̯', = 'i̯ɑʊ̯', = 'i̯ɑʊ̯', = 'i̯ɛn', = 'i̯ɛn', = 'u̯a̠n', = 'u̯a̠n', = 'y̯ɛn', = 'y̯ɛn', = 'ɑŋ', = 'y̯œ', = 'u̯eɪ̯', = 'i̯oʊ̯', = 'in', = 'u̯ən', = 'yn', = 'ɤŋ', = 'iŋ', = 'ʊŋ', = 'ɑɻ', = 'ɑɻ', = 'jɑɻ', = 'jɑɻ', = 'wɑɻ', = 'wɑɻ', = 'aʊɻʷ', = 'jɛɻ', = 'jɛɻ', = 'wɔɻ', = 'wɔɻ', = 'ɥɛɻ', = 'ɥɛɻ', = 'əɻ', = 'əɻ', = 'wəɻ', = 'wəɻ', = 'ɤʊɻʷ', = 'jɤʊɻ', = 'jəɻ', = 'ɥəɻ', = 'ɥəɻ', = 'jəɻ', = 'wuɻ', = 'ɥəɻ',
= 'i̯ɔ', = 'i̯a̠', = 'i̯a̠', = 'u̯a̠', = 'u̯a̠', = 'aɪ̯', = 'ɑʊ̯', = 'a̠n', = 'i̯ɛ', = 'i̯ɛ', = 'u̯ɔ', = 'u̯ɔ', = 'ɥ̯œ', = 'ɥ̯œ', = 'ɥ̯œ', = 'eɪ̯', = 'u̯eɪ̯', = 'oʊ̯', = 'i̯oʊ̯', = 'ən', = 'in', = 'u̯ən', = 'yn', = 'yn', = 'i', = 'u', = 'y', = 'm̩', = 'ŋ̩', = 'ŋ̩', = 'ŋ̩', = 'ɛ', = 'ɛ', = 'ɑɻ', = 'ɤɻ', = 'wɔɻ', = 'iəɻ', = 'uɻ', = 'yəɻ', = 'yəɻ',
= 'a̠', = 'ɤ', = 'u̯ɔ', = 'i', = 'u', = 'y', = 'y', = 'm̩', = 'm̩', = 'n̩', = 'n̩', = 'n̩', = 'ɛ'
}
local ipa_null = {
= true, = true, = true, = true,
= true, = true, = true, = true,
= true, = true, = true,
= true, = true, = true,
}
local ipa_tl_ts = {
= '²', = '³', = '⁴', = '¹', = '¹'
}
local ipa_third_t_ts = {
= '²¹¹', = '²¹⁴⁻³⁵', = '²¹⁴', = '²¹¹', = '²¹¹', = '²¹¹', = '²¹¹', = '²¹¹'
}
local ipa_t_values = {
= '⁵¹', = '⁵¹', = '⁵⁵', = '³⁵', = '³⁵', = '³⁵'
}
local tone = {}
local tone_cat = {}
text = gsub(export.py_transform(text), '', '')
text = gsub(text, ' +', ' ')
local p = split(text, " ")
for i = 1, #p do
tone_cat = m_zh.tone_determ(p)
p = gsub(p, '.?', py_detone)
if p == '一' then
tone_cat = (m_zh.tone_determ(p) == '4' or p == 'ge') and '1-2' or '1-4'
p = 'yi'
elseif p == '不' then
tone_cat = (m_zh.tone_determ(p) == '4') and '4-2' or '4'
p = 'bu'
end
end
tone_cat.length = #tone_cat
for i, item in ipairs(p) do
if ipa_null then item = 'ˀ' .. item end
item = gsub(item, '()u', '%1ü')
if item == 'ng' then
item = ipa_final
else
item = gsub(item, '^(ˀ?)(?h?)(.+)$',
function(a, b, c) return a ..
(ipa_initial or error(("Unrecognised initial: \"%s\""):format(b))) ..
(ipa_final or error(("Unrecognised final: \"%s\". Are you missing an apostrophe before the null-initial syllable, or using an invalid Pinyin final?"):format(c))) end)
end
item = gsub(item, '(ʈ?͡?ʰ?)i', '%1ʐ̩')
item = gsub(item, '(t?͡?sʰ?)i', '%1z̩')
item = gsub(item, 'ˀu̯ɔ', 'ˀ̯ɔ')
item = gsub(item, 'ʐʐ̩', 'ʐ̩')
local curr_tone_cat, next_tone_cat = tone_cat, tone_cat
if curr_tone_cat == '5' then
item = gsub(item, '^()()', function(a, b) return ipa_initial_tl .. b end)
item = gsub(item, '^(͡)()', function(a, b) return ipa_initial_tl .. b end)
item = gsub(item, 'ɤ$', 'ə')
tone = ipa_tl_ts] or ""
elseif curr_tone_cat == '3' then
if i == tone_cat.length then
if i == 1 then tone = '²¹⁴' else tone = '²¹' end
else
tone = ipa_third_t_ts
end
elseif curr_tone_cat == '4' and next_tone_cat == '4' then
tone = '⁵³'
elseif curr_tone_cat == '4' and next_tone_cat == '1-4' then
tone = '⁵³'
elseif curr_tone_cat == '1-4' and next_tone_cat == '4' then
tone = '⁵³'
else
tone = ipa_t_values
end
p = item .. tone
end
return table.concat(p, " ")
end
function export.py_number_to_mark(text)
local priority = { "a", "o", "e", "ê", "i", "u", "ü" }
local toneMark = { = "̄", = "́", = "̌", = "̀", = "", = "", = "" }
local mark = toneMark?$")]
local toneChars = ""
text = gsub(text, "?$", "")
for _, letter in ipairs(priority) do
text = gsub(text, letter, letter .. mark)
if find(text, toneChars) then break end
end
return mw.ustring.toNFC(gsub(text, "i("..toneChars..")u", "iu%1"))
end
function export.yale_number_to_mark(text)
local priority = { "a", "o", "e", "ê", "i", "u", "ü", "r", "z" }
local toneMark = { = "̄", = "́", = "̌", = "̀", = "", = "", = "" }
local mark = toneMark?$")]
local toneChars = ""
text = gsub(text, "?$", "")
for _, letter in ipairs(priority) do
text = gsub(text, letter, letter .. mark)
if find(text, toneChars) then break end
end
return mw.ustring.toNFC(gsub(text, "i("..toneChars..")u", "iu%1"))
end
function export.py_zhuyin(text)
local zhuyin_initial = {
= 'ㄅ', = 'ㄆ', = 'ㄇ', = 'ㄈ',
= 'ㄉ', = 'ㄊ', = 'ㄋ', = 'ㄌ',
= 'ㄍ', = 'ㄎ', = 'ㄏ',
= 'ㄐ', = 'ㄑ', = 'ㄒ',
= 'ㄗ', = 'ㄘ', = 'ㄙ', = 'ㄖ',
= 'ㄓ', = 'ㄔ', = 'ㄕ',
= ''
}
local zhuyin_final = {
= 'ㄩㄢ', = 'ㄧㄤ', = 'ㄧㄤ', = 'ㄨㄤ', = 'ㄨㄤ', = 'ㄧㄥ', = 'ㄨㄥ', = 'ㄩㄥ', = 'ㄩㄥ',
= 'ㄨㄞ', = 'ㄨㄞ', = 'ㄧㄞ', = 'ㄧㄠ', = 'ㄧㄠ', = 'ㄧㄢ', = 'ㄧㄢ', = 'ㄨㄢ', = 'ㄨㄢ', = 'ㄩㄢ', = 'ㄤ', = 'ㄩㄝ', = 'ㄨㄟ', = 'ㄧㄡ', = 'ㄧㄣ', = 'ㄨㄣ', = 'ㄩㄣ', = 'ㄥ', = 'ㄧㄥ', = 'ㄨㄥ',
= 'ㄧㄛ', = 'ㄧㄚ', = 'ㄧㄚ', = 'ㄨㄚ', = 'ㄨㄚ', = 'ㄞ', = 'ㄠ', = 'ㄢ', = 'ㄧㄝ', = 'ㄧㄝ', = 'ㄨㄛ', = 'ㄨㄛ', = 'ㄩㄝ', = 'ㄩㄝ', = 'ㄟ', = 'ㄨㄟ', = 'ㄡ', = 'ㄧㄡ', = 'ㄣ', = 'ㄧㄣ', = 'ㄨㄣ', = 'ㄩㄣ', = 'ㄧ', = 'ㄨ', = 'ㄩ',
= 'ㄚ', = 'ㄜ', = 'ㄛ', = 'ㄧ', = 'ㄨ', = 'ㄩ', = 'ㄝ', = ''
}
local zhuyin_er = {
= 'ㄦ', = ''
}
local zhuyin_tone = {
= '', = 'ˊ', = 'ˇ', = 'ˋ', = '˙', = '˙'
}
if type(text) == 'table' then
if text.args == '' then
text = mw.title.getCurrentTitle().text
return ""
else
text = text.args
end
end
breve_error(text)
text = export.py_transform(text, true)
text = gsub(text, '()u', '%1ü')
text = gsub(text, '(h?)i', '%1')
text = gsub(text, '()i', '%1')
local word = split(text, " ", true)
for i, syllable in ipairs(word) do
if find(syllable, '^$') then
syllable = gsub(syllable, '^()()$', function(a, b) return (({ = 'ㄫ', = 'ㄏㄇ'}) or a) .. zhuyin_tone end)
elseif find(syllable, '^hng$') then
syllable = gsub(syllable, '^hng()$', function(number) return 'ㄏㄫ' .. zhuyin_tone end)
elseif find(syllable, '^er$') then
syllable = gsub(syllable, '^er()$', function(number) return 'ㄦ' .. zhuyin_tone end)
else
syllable = gsub(syllable, '^(?h?)(????)(r?)()$',
function(a, b, c, d) return zhuyin_initial .. zhuyin_final .. zhuyin_tone .. zhuyin_er end)
end
if find(syllable, '') then
error(("Zhuyin conversion unsuccessful: \"%s\". Are you using a valid Pinyin syllable? Is the text using a breve letter instead of a caron one?"):format(syllable))
end
word = syllable
end
text = gsub(table.concat(word, " "), ' , ', ', ')
return text
end
function export.zhuyin_py(text)
local zhuyin_py_initial = {
= "b", = "p", = "m", = "f",
= "d", = "t", = "n", = "l",
= "g", = "k", = "h",
= "j", = "q", = "x",
= "zh", = "ch", = "sh", = "r",
= "z", = "c", = "s",
= ""
}
local zhuyin_py_final = {
= 'a', = 'o', = 'e', = 'ê', = 'ai', = 'ei', = 'ao', = 'ou', = 'an', = 'en', = 'ang', = 'eng',
= 'i', = 'ia', = 'io', = 'ie', = 'iai', = 'iao', = 'iu', = 'ian', = 'in', = 'iang', = 'ing',
= 'u', = 'ua', = 'uo', = 'uai', = 'ui', = 'uan', = 'un', = 'uang', = 'ong',
= 'ü', = 'ue', = 'üe', = 'üan', = 'ün', = 'iong',
= 'er', = 'ng', = 'm', = 'i'
}
local zhuyin_py_tone = {
= "\204\129", = "\204\140", = "\204\128", = "", = "\204\132"
}
if type(text) == "table" then text = text.args end
local word = split(text, " ", true)
for i, syllable in ipairs(word) do
syllable = gsub(syllable, '^()(?)$', '%1ㄧ%2')
word = gsub(syllable, '(?)(?)(?)(ㄦ?)', function(initial, final, tone, erhua)
initial = zhuyin_py_initial
final = zhuyin_py_final
if erhua ~= '' then
final = final .. 'r'
end
if initial == '' then
final = final:gsub('^()(n?g?)$', function(a, b) return a:gsub('', { = 'yi', = 'wu'}) .. b end)
final = final:gsub('^(w?u)()$', 'ue%2')
final = final:gsub('^iu$', 'iou')
final = final:gsub('^()', { = 'y', = 'w'})
final = final:gsub('^ong', 'weng')
final = gsub(final, '^ü', 'yu')
end
if initial:find('') then
final = gsub(final, '^ü', 'u')
end
local tone = zhuyin_py_tone
if final:find('') then
final = final:gsub("()", "%1" .. tone)
elseif final:find('i') then
final = final:gsub("(i)", "%1" .. tone)
elseif final:find('') then
final = final:gsub("()", "%1" .. tone)
else
final = gsub(final, "^(?)(.)", "%1" .. "%2" .. tone)
end
return initial .. final
end)
end
return mw.ustring.toNFC(table.concat(word, " "))
end
function export.py_wg(text)
local py_wg_initial = {
= "p", = "p’",
= "t", = "t’",
= "k", = "k’",
= "chi", = "ch’i", = "hsi",
= "ts", = "ts’", = "j",
= "ch", = "ch’",
}
local py_wg_final = {
?)e()"] = "%1ê%2",
= "ê",
)an$"] = "%1en",
= "%1ung",
)e$"] = "%1eh",
e"] = "üeh",
= "rh",
= "eh",
= "ih",
= "i",
}
local py_wg_syl = {
= "i", = "i", = "ü",
= "%1o",
)uo"] = "%1o",
= "%1o",
= "tzŭ", = "tz’ŭ", = "ssŭ",
’?)ê$"] = "%1o",
= "yen",
= "yu", = "i",
)ih"] = "%1i",
= "t’i" , = "p’i"
}
if type(text) == 'table' then text = text.args end
local text = gsub(export.py_transform(text, true), '', '')
text = gsub(gsub(text, ' +', ' '), '', { = 'yi1', = 'bu4'})
text = gsub(text, '()u', '%1ü')
local p = split(text, " ", true)
for i = 1, #p do
p = gsub(p, '^(?h?)(.+)()$', function(initial, final, tone)
for text, replace in pairs(py_wg_final) do
final = gsub(final, text, replace)
end
local untoned = (py_wg_initial or initial) .. final
for text, replace in pairs(py_wg_syl) do
untoned = gsub(untoned, text, replace)
end
untoned = gsub(untoned, "k(’?)ui", "k%1uei")
return untoned .. '<sup>' .. tone .. '</sup>' end)
end
return table.concat(p, " ")
end
function export.py_yale(text)
local py_yale_initial = {
= "chh", = "sy",
= "dz", = "ts",
= "jh"
}
local py_yale_final = {
= "yung",
= "ung",
= "au",
= "yau",
= "you",
)"] = "y%1",
)$"] = "we%1",
)"] = "w%1",
= "o",
)"] = "w%1",
)"] = "yw%1",
?)$"] = "yu%1",
= "e"
}
local py_yale_syl = {
= "jr",
= "j",
= "chr",
= "ch",
= "shr",
= "r",
= "dz",
= "tsz",
= "sz",
= "y",
= "shwun",
= "rwun",
= "lwun",
= "gwun",
)o$"] = "%1wo"
}
if type(text) == 'table' then text = text.args end
local text = gsub(export.py_transform(text, true), '', '')
text = gsub(gsub(text, ' +', ' '), '', { = 'yi1', = 'bu4'})
text = gsub(text, '()u', '%1ü')
local p = split(text, " ", true)
for i = 1, #p do
p = gsub(p, '^(?h?)(.+)()$', function(initial, final, tone)
for text, replace in pairs(py_yale_final) do
final = gsub(final, text, replace)
end
local untoned = (py_yale_initial or initial) .. final
for text, replace in pairs(py_yale_syl) do
untoned = gsub(untoned, text, replace)
end
untoned = gsub(untoned, "k('?)ui", "k%1uei")
return export.yale_number_to_mark(untoned .. tone) end)
end
return table.concat(p, " ")
end
function export.py_efeo(text)
local py_efeo_initial = {
= "p", = "p’",
= "t", = "t’",
= "k", = "k’", = "j",
= "chv", = "tchv", = "tch’v",
= "tsv", = "k/ts",
= "ts’v", = "k’/ts’",
= "sv", = "h/s"
}
local py_efeo_final = {
= "eou",
= "ou",
)"] = "ou%1",
)$"] = "oue%1",
)an$"] = "%1en",
= "ieou",
= "eul",
}
local py_efeo_syl = {
g?)$"] = "nga%1",
$"] = "ngo",
= "ngen%1",
= "ngeou",
= "%1ö",
= "%1ö",
= "%1e",
= "%1eu",
= "sseu",
= "je",
)eng"] = "%1ong",
= "leang",
= "leao",
= "k%1ia",
= "hia",
= "k%1iai, k%1ie, ts%1ie",
= "hiai, hie, sie",
= "k%1iong",
= "hiong",
= "k%1io, k%1iue, ts%1io, ts%1iue",
= "%1o",
’?)ouo"] = "%1o",
’?)e$"] = "%1ö",
’?)e$"] = "%1o, %1ö",
= "k%1/ts%1iu%2",
= "h/siu%1",
)ü"] = "%1iu",
= "liue, lio",
= "nio",
= "yu",
= "yeou"
}
local py_efeo_cleanup = {
= "",
= "k%1, ts%1",
= "k’%1, ts’%1",
= "h%1, s%1"
}
if type(text) == 'table' then text = text.args end
local text = gsub(export.py_transform(text, true), '', '')
text = gsub(gsub(text, ' +', ' '), '', { = 'yi1', = 'bu4'})
text = gsub(text, '()u', '%1ü')
local p = split(text, " ", true)
for i = 1, #p do
p = gsub(p, '^(?h?)(.+)()$', function(initial, final, tone)
for text, replace in pairs(py_efeo_final) do
final = gsub(final, text, replace)
end
local untoned = (py_efeo_initial or initial) .. final
for text, replace in pairs(py_efeo_syl) do
untoned = gsub(untoned, text, replace)
end
for text, replace in pairs(py_efeo_cleanup) do
untoned = gsub(untoned, text, replace)
end
untoned = gsub(untoned, "k('?)ui", "k%1uei")
return untoned end)
end
return table.concat(p, " ")
end
local function temp_bg(text, bg)
if bg == 'y' then
return '<' .. text .. '>'
end
return text
end
local function make_bg(text, bg)
if bg == 'y' then
return '<span style="background-color:#F5DEB3">' .. text .. '</span>'
else
return text
end
end
function export.py_gwoyeu(text, original_text)
local initials = {
= 'b', = 'p', = 'm', = 'f',
= 'd', = 't', = 'n', = 'l',
= 'g', = 'k', = 'h',
= 'j', = 'ch', = 'sh',
= 'j', = 'ch', = 'sh', = 'r',
= 'tz', = 'ts', = 's',
= 'i', = 'u',
= ''
}
local finals = {
= 'a', = 'ai', = 'au', = 'an', = 'ang', = 'e', = 'ei', = 'ou', = 'en', = 'eng', = 'o',
= 'ia', = 'iau', = 'ian', = 'iang', = 'ie', = 'iou', = 'in', = 'ing', = 'i',
= 'ua', = 'uai', = 'uan', = 'uang', = 'uo', = 'uei', = 'uen', = 'ong', = 'u',
= 'y', = 'iuan', = 'iue', = 'iun', = 'iong', = 'iu',
--erhua
= 'al', = 'al', = 'aul', = 'al', = 'angl', = 'el', = 'eil', = 'oul', = 'el', = 'engl', = 'ol',
= 'ial', = 'iaul', = 'ial', = 'iangl', = 'iel', = 'ioul', = 'iel', = 'iengl', = 'iel',
= 'ual', = 'ual', = 'ual', = 'uangl', = 'uol', = 'ueil', = 'uel', = 'ongl', = 'ul',
= 'el', = 'iual', = 'iuel', = 'iul', = 'iongl', = 'iuel',
}
if type(text) == 'table' then text = text.args end
if text:find('^%s') or text:find('%s$') then error('invalid spacing') end
local words = split(text, " ")
local count = 0
for i, word in ipairs(words) do
local uppercase
if word:find('^%u') then uppercase = true else uppercase = false end
word = export.py_transform(word, true, true)
word = gsub(word, "()", "%1 ")
word = gsub(word, " $", "")
word = gsub(word, '()', ' %1 ')
word = gsub(word, ' +', ' ')
word = gsub(word, ' $', '')
word = gsub(word, '^ ', '')
local syllables = split(word, " ")
for j, syllable in ipairs(syllables) do
count = count + 1
if not mw.ustring.find(syllable, '^+$') then
local current = sub(mw.title.getCurrentTitle().text, count, count)
if current == '一' or current == '七' or current == '八' or current == '不' then
syllable = gsub(current, '.', { = 'i', = 'chi', = 'ba', = 'bu'})
else
local initial, final, tone = '', '', ''
syllable = gsub(syllable, '()u', '%1ü')
syllable = gsub(syllable, '^(h?)i(r?)$', '%1ɨ%2')
if mw.ustring.find(syllable, '(?h?)(??g?r?)()') then
syllable = gsub(syllable, '(?h?)(??g?r?)()', function(a, b, c)
initial = initials or error('Unrecognised initial:' .. a); final = finals or error('Unrecognised final:' .. b); tone = c
return (initial .. final .. tone) end)
elseif not find(mw.title.getCurrentTitle().text, "^$") then
error('Unrecognised syllable:' .. syllable)
end
local original = initial..final..tone
if initial:find('^$') then
final = initial .. final
initial = ''
end
final = gsub(final, '()%1', '%1')
local len = len(initial) + len(final)
local detone = initial..final
local replace = detone
local fullstop = false
if tone == 5 or tone == '5' then
fullstop = true
if original_text then
tone = split(export.py_transform(original_text, true), ' '):match('')
else tone = 1 end
if tone == 5 or tone == '5' then
tone = m_zh.tone_determ(m_zh.py(current))
end
end
if tone == 1 or tone == '1' then
if initial == 'l' or initial == 'm' or initial == 'n' or initial == 'r' then
replace = initial .. 'h' .. sub(detone, 2, len)
else
replace = detone
end
elseif tone == 2 or tone == '2' then
if not (initial == 'l' or initial == 'm' or initial == 'n' or initial == 'r') then
if final:sub(1, 1) == 'i' or final:sub(1, 1) == 'u' then
replace = gsub(detone, '', { = 'y', = 'w'}, 1)
if replace:sub(len, len) == 'y' or replace:sub(len, len) == 'w' then
replace = gsub(replace, '$', { = 'yi', = 'wu'})
end
else
replace = detone .. 'r'
end
else
replace = detone
end
elseif tone == 3 or tone == '3' then
if detone:find('^') then
detone = detone:gsub('^', { = 'yi', = 'wu'})
end
if final:find('') and not final:find('^') and not final:find('^') then
replace = detone:gsub('', { = 'e', = 'o'}, 1)
else
if final:find('a') then replace = detone:gsub('a', 'aa', 1)
elseif final:find('o') then replace = detone:gsub('o', 'oo', 1)
elseif final:find('e') then replace = detone:gsub('e', 'ee', 1)
elseif final:find('i') then replace = detone:gsub('i', 'ii', 1)
elseif final:find('u') then replace = detone:gsub('u', 'uu', 1)
elseif final:find('y') then replace = detone:gsub('y', 'yy', 1)
else error('Unrecognised final:'..final)
end
end
elseif tone == 4 or tone == '4' then
if detone:find('^') then
detone = detone:gsub('^', { = 'yi', = 'wu'})
end
if detone:find('g?$') then
replace = detone:gsub('g?$', { = 'y', = 'w', = 'll', = 'nn', = 'nq'})
else
replace = detone .. 'h'
end
replace = replace:gsub('yi()', 'y%1')
replace = replace:gsub('wu()', 'w%1')
end
if fullstop then replace = '.' .. replace end
syllables = syllable:gsub(original, replace)
end
end
end
words = table.concat(syllables, "")
if uppercase then
words = gsub(words, '^%l', mw.ustring.upper)
end
end
return table.concat(words, " ")
end
function export.py_format(text, cap, bg, simple, nolink)
if cap == false then cap = nil end
if bg == false then bg = 'n' else bg = 'y' end
if simple == false then simple = nil end
if nolink == false then nolink = nil end
text = mw.ustring.toNFD(text)
local phon = text
local title = mw.title.getCurrentTitle().text
local cat = ''
local spaced = mw.ustring.toNFD(export.py_transform(text))
local space_count
spaced, space_count = gsub(spaced, ' ', '@')
local consec_third_count
for _ = 1, space_count do
spaced, consec_third_count = gsub(spaced, "(+)̌(*)@(+̌)", function(a, b, c)
return temp_bg(a..'́'..b, bg)..'@'..c end, 1)
if consec_third_count > 0 then
phon = gsub(spaced, '@', '')
end
end
if title:find('一') and not text:find('一') and not simple then
cat = cat .. ']'
end
if text:find('') and not simple then
text = gsub(text, '$', { = 'yī', = 'bù'})
phon = gsub(phon, '$', { = 'yī', = 'bù'})
if find(text, '一') then
if find(text, '一*') then
cat = cat .. ']'
phon = gsub(phon, '一(*)', function(a) return temp_bg('yì', bg) .. a end)
text = gsub(text, '一(*)', 'yī%1')
end
if find(text, '一*̀') or find(text, '一ge$') or find(text, '一ge') then
cat = cat .. ']'
phon = gsub(phon, '一(*̀)', function(a) return temp_bg('yí', bg) .. a end)
phon = gsub(phon, '一ge', temp_bg('yí', bg) .. 'ge')
text = gsub(text, '一(*)', 'yī%1')
end
end
if find(text, '不 ??h?*̀') then
cat = cat .. ']'
phon = gsub(phon, '不( ??h?*̀)', function(a) return temp_bg('bú', bg) .. a end)
end
end
text = gsub(text, '', { = 'yī', = 'bù'})
text = gsub(text, '兒', function() return make_bg('r', bg) end) -- character is deleted
phon = gsub(phon, '<(+)>', '<span style="background-color:#F5DEB3">%1</span>')
if not simple then
if cap then
text = gsub(text, '^%l', string.upper)
phon = gsub(phon, '^%l', string.upper)
end
if not nolink then
text = ']'
end
if '', { = 'yī', = 'bù'}) .. ']]' ~= text then
phon = gsub(phon, '', { = 'yī', = 'bù'})
text = text .. ' '
end
if mw.title.getCurrentTitle().nsText ~= 'Template' and not nolink then
text = text .. cat
end
end
return mw.ustring.toNFC(text)
end
function export.make_tl(original_text, tl_pos, bg, cap)
if bg == false then bg = 'n' else bg = 'y' end
local _, countoriginal = gsub(original_text, " ", " ")
local spaced = export.py_transform(original_text)
if sub(spaced, -1, -1) == ' ' then spaced = sub(spaced, 1, -2) end
local _, count = gsub(spaced, " ", " ")
local index = {}
local start, finish
local pos = 1
for i = 1, count, 1 do
if i ~= 1 then pos = (index + 1) end
index = mw.ustring.find(spaced, ' ', pos)
end
if tl_pos == 2 then
start = index - count + countoriginal + 2
finish = index - count + countoriginal
elseif tl_pos == 3 then
start = index - count + countoriginal + 3
finish = index - count + countoriginal + 1
else
start = count == 0 and 1 or (index - count + countoriginal + 1)
finish = -1
end
local text = (sub(original_text, 1, start-1) .. make_bg(gsub(sub(original_text, start, finish), '.', py_detone), bg))
if finish ~= -1 then text = (text .. sub(original_text, finish+1, -1)) end
if cap == true then text = gsub(text, '^%l', string.upper) end
return text
end
function export.tag(first, second, third, fourth, fifth)
local text = "(''"
local tag = {}
local tagg = first or "Standard Chinese"
tag = (second ~= '') and second or "Standard Chinese"
tag = (third ~= '') and third or nil
tag = (fourth ~= '') and fourth or nil
tag = (fifth ~= '') and fifth or nil
text = text .. ((tagg == '') and table.concat(tag, ", ") or tagg) .. "'')"
text = gsub(text, 'Standard Chinese', "]")
text = gsub(text, 'Beijing', "]")
text = gsub(text, 'Mainland', "]")
text = gsub(text, 'Taiwan', "]")
text = gsub(text, 'Min Nan', "]")
text = gsub(text, 'erhua', "]")
return text
end
function export.straitdiff(text, pron_ind, tag)
local conv_text = text
for i = 1, #text do
if m_zh_data().MT then conv_text = 'y' end
end
if tag == 'tag' then
conv_text = (conv_text == 'y') and m_zh_data().MT_tag')] or ''
elseif pron_ind == 1 or pron_ind == 2 or pron_ind == 3 or pron_ind == 4 or pron_ind == 5 then
local reading = {}
for a, b in pairs(m_zh_data().MT) do
reading = b
if reading then reading = gsub(reading, "^()", "'%1") end
end
conv_text = gsub(text, '.', reading)
text = gsub(text, "^'", "")
text = gsub(text, " '", " ")
if conv_text == text and tag == 'exist' then return nil end
end
conv_text = gsub(conv_text, "^'", "")
return conv_text
end
function export.str_analysis(text, conv_type, sichuan)
if type(text) == 'table' then text, conv_type = text.args, (text.args or "") end
local MT = m_zh_data().MT
text = gsub(text, '=', '—')
text = gsub(text, ',', '隔')
text = gsub(text, '隔 ', ', ')
if conv_type == 'head' or conv_type == 'link' then
if find(text, ', cap—') then
text = gsub(text, '', { = 'Yī', = 'Bù'})
end
text = gsub(text, '', { = 'yī', = 'bù'})
end
local comp = split(text, '隔', true)
local reading = {}
local alternative_reading = {}
local zhuyin = {}
--[[
-- not used
local param = {
'1n', '1na', '1nb', '1nc', '1nd', 'py', 'cap', 'tl', 'tl2', 'tl3', 'a', 'audio', 'er', 'ertl', 'ertl2', 'ertl3', 'era', 'eraudio',
'2n', '2na', '2nb', '2nc', '2nd', '2py', '2cap', '2tl', '2tl2', '2tl3', '2a', '2audio', '2er', '2ertl', '2ertl2', '2ertl3', '2era', '2eraudio',
'3n', '3na', '3nb', '3nc', '3nd', '3py', '3cap', '3tl', '3tl2', '3tl3', '3a', '3audio', '3er', '3ertl', '3ertl2', '3ertl3', '3era', '3eraudio',
'4n', '4na', '4nb', '4nc', '4nd', '4py', '4cap', '4tl', '4tl2', '4tl3', '4a', '4audio', '4er', '4ertl', '4ertl2', '4ertl3', '4era', '4eraudio',
'5n', '5na', '5nb', '5nc', '5nd', '5py', '5cap', '5tl', '5tl2', '5tl3', '5a', '5audio', '5er', '5ertl', '5ertl2', '5ertl3', '5era', '5eraudio'
}
--]]
if conv_type == '' then
return comp
elseif conv_type == 'head' or conv_type == 'link' then
for i, item in ipairs(comp) do
if not find(item, '—') then
if find(item, '') then
local M, T, t = {}, {}, {}
for a, b in pairs(MT) do
M = b; T = b; t = b;
M = gsub(M, "^()", "'%1")
T = gsub(T, "^()", "'%1")
if t then t = gsub(t, "^()", "'%1") end
end
local mandarin = gsub(item, '.', M)
local taiwan = gsub(item, '.', T)
mandarin = gsub(mandarin, "^'", "")
mandarin = gsub(mandarin, " '", " ")
if conv_type == 'link' then return mandarin end
taiwan = gsub(taiwan, "^'", "")
taiwan = gsub(taiwan, " '", " ")
local tt = gsub(item, '.', t)
if find(text, 'cap—') then
mandarin = gsub(mandarin, '^%l', string.upper)
taiwan = gsub(taiwan, '^%l', string.upper)
tt = gsub(tt, '^%l', string.upper)
end
if tt == item then
zhuyin = export.py_zhuyin(mandarin, true) .. ', ' .. export.py_zhuyin(taiwan, true)
reading = mandarin .. ']], [[' .. taiwan
else
tt = gsub(tt, "^'", "")
tt = gsub(tt, " '", " ")
zhuyin = export.py_zhuyin(mandarin, true) .. ', ' .. export.py_zhuyin(taiwan, true) .. ', ' .. export.py_zhuyin(tt, true)
reading = mandarin .. ']], ], [[' .. tt
end
else
if conv_type == 'link' then return item end
zhuyin = export.py_zhuyin(item, true)
reading = item
if len(mw.title.getCurrentTitle().text) == 1 and #mw.text.split(export.py_transform(item), " ") == 1 then
alternative_reading = ") .. "|" .. mw.ustring.gsub(m_zh.py_transf(reading), '()', '<sup>%1</sup>') .. "]]"
end
end
if reading ~= '' then reading = ' .. ']]' end
end
comp = item
if conv_type == 'link' then return comp end
end
local id = m_zh.ts_determ(mw.title.getCurrentTitle().text)
local accel
if id == 'trad' then
accel = '<span class="form-of pinyin-t-form-of transliteration-' .. m_zh.ts(mw.title.getCurrentTitle().text) .. '" lang="cmn">'
elseif id == 'simp' then
accel = '<span class="form-of pinyin-s-form-of transliteration-' .. m_zh.st(mw.title.getCurrentTitle().text) .. '" lang="cmn">'
elseif id == 'both' then
accel = '<span class="form-of pinyin-ts-form-of" lang="cmn">'
end
local result = sichuan and sichuan ~= "" and "*: <small>('']'')</small>\n*::" or "*:"
result = result .. "<small>('']'')</small>: <code>" .. accel .. gsub(table.concat(reading, ", "), ", ,", ",") .. "</span>"
if alternative_reading then
result = result .. " (" .. table.concat(alternative_reading, ", ") .. ")"
end
result = result .. (sichuan and sichuan ~= "" and "</code>\n*::" or "</code>\n*:")
result = result .. "<small>('']'')</small>: " .. '<span lang="zh" class="Bopo">' .. gsub(table.concat(zhuyin, ", "), ", ,", ",") .. "</span>"
return result
elseif conv_type == '2' or conv_type == '3' or conv_type == '4' or conv_type == '5' then
if not find(text, '隔') or (comp and find(comp, '—')) then
return ''
else
return comp
end
else
for i = 1, #comp, 1 do
local target = '^' .. conv_type .. '—'
if find(comp, target) then
text = gsub(comp, target, '')
return text
end
end
text = ''
end
return text
end
function export.homophones(pinyin)
local text = ''
if mw.title.getCurrentTitle().nsText == '' then
local args = hom_data.list
text = '<div style="visibility:hidden; float:left"><sup><span style="color:#FFF">edit</span></sup></div>'
for i, term in ipairs(args) do
if i > 1 then
text = text .. "<br>"
end
if mw.title.new(term).exists and term ~= mw.title.getCurrentTitle().text then
local forms = { term }
local content = mw.title.new(term):getContent()
local template = match(content, "{{zh%-forms*}}")
if template then
local simp = match(template, "|s=()+")
if simp then
table.insert(forms, simp)
end
for tradVar in mw.ustring.gmatch(template, "|t=()+") do
table.insert(forms, tradVar)
end
for simpVar in mw.ustring.gmatch(template, "|s=()+") do
table.insert(forms, simpVar)
end
term = table.concat(forms, "/")
end
end
text = text .. mw.getCurrentFrame():expandTemplate{ title = "Template:zh-l", args = { term, tr = "-" } }
end
text = text .. ']'
end
return text
end
local function erhua(word, erhua_pos, pagename)
local title = split(pagename, '')
local linked_title = ''
local syllable = split(export.py_transform(word), " ")
local count = table.getn(syllable)
erhua_pos = find(erhua_pos, '') and split(erhua_pos, ';') or { count }
for _, pos in ipairs(erhua_pos) do
pos = tonumber(pos)
title = title .. '兒'
syllable = syllable .. 'r'
end
local title = table.concat(title)
if mw.title.new(title).exists then
linked_title = ' (' .. m_zh.link(nil, nil, {title, tr="-"}) .. ')'
end
word = table.concat(syllable, "")
return (export.tag('', '', 'erhua-ed') .. linked_title), word
end
function export.make(frame)
local args = frame:getParent().args
return export.make_args(args)
end
function export.make_args(args)
local pagename = mw.title.getCurrentTitle().text
local text = ''
local reading = {args or '', args or '', args or '', args or '', args or ''}
args = ine(args)
if reading ~= '' then
local title = export.tag((args or ''), (args or ''), (args or export.straitdiff(args, 1, 'tag')), (args or ''), (args or ''))
local pinyin = export.straitdiff(reading, 1, '')
text = text .. export.make_table(title, pinyin, (args or ''), (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''))
if args and args ~= '' then
title, pinyin = erhua(pinyin, args, pagename)
text = text .. export.make_table(title, pinyin, '', (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true)
end
end
if reading ~= '' or export.straitdiff(reading, 2, 'exist') then
if args and args ~= '' then tagb = args else tagb = export.straitdiff(args, 2, 'tag') end
title = export.tag((args or ''), (args or ''), tagb, (args or ''), (args or ''))
pinyin = (reading ~= '') and reading or export.straitdiff(reading, 2, '')
text = text .. export.make_table(title, pinyin, (args or ''), (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true) .. ', 1, '') or args) .. ']]'
if args and args ~= '' then
title, pinyin = erhua(pinyin, args, pagename)
text = text .. export.make_table(title, pinyin, '', (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true)
end
if reading ~= '' or export.straitdiff(reading, 3, 'exist') then
if args and args ~= '' then tagb = args else tagb = export.straitdiff(args, 3, 'tag') end
title = export.tag((args or ''), (args or ''), tagb, (args or ''), (args or ''))
if reading ~= '' then pinyin = reading else pinyin = export.straitdiff(reading, 3, '') end
text = text .. export.make_table(title, pinyin, (args or ''), (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true)
if args and args ~= '' then
title, pinyin = erhua(pinyin, args, pagename)
text = text .. export.make_table(title, pinyin, '', (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true)
end
if reading ~= '' or export.straitdiff(reading, 4, 'exist') then
if args and args ~= '' then tagb = args else tagb = export.straitdiff(args, 4, 'tag') end
title = export.tag((args or ''), (args or ''), tagb, (args or ''), (args or ''))
if reading ~= '' then pinyin = reading else pinyin = export.straitdiff(reading, 4, '') end
text = text .. export.make_table(title, pinyin, (args or ''), (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true)
if args and args ~= '' then
title, pinyin = erhua(pinyin, args, pagename)
text = text .. export.make_table(title, pinyin, '', (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true)
end
if reading ~= '' or export.straitdiff(reading, 5, 'exist') then
if args and args ~= '' then tagb = args else tagb = export.straitdiff(args, 5, 'tag') end
title = export.tag((args or ''), (args or ''), tagb, (args or ''), (args or ''))
if reading ~= '' then pinyin = reading else pinyin = export.straitdiff(reading, 5, '') end
text = text .. export.make_table(title, pinyin, (args or ''), (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true)
if args and args ~= '' then
title, pinyin = erhua(pinyin, args, pagename)
text = text .. export.make_table(title, pinyin, '', (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true)
end
end
end
end
end
if (args or '') .. (args or '') .. (args or '') .. (args or '') .. (args or '') .. (args or '') ~= '' then
text = text .. ', 1, '') .. ']]'
end
return text
end
function export.make_table(title, pinyin, py, cap, tl, tl2, tl3, a, novariety)
py = ine(py);cap = ine(cap);tl = ine(tl);tl2 = ine(tl2);tl3 = ine(tl3);a = ine(a);novariety = ine(novariety)
local text = ''
local pinyin_simple_fmt = export.py_format(pinyin, false, false, true)
local pinyin_simple_fmt_nolink = export.py_format(pinyin, false, false, true, true)
if not novariety then text = text .. '* ]' else text = text .. '<br>' end
text = text .. '\n** <small>' .. title .. '</small>'
local hom_found
if hom_data.list then
hom_found = true
else
hom_found = false
text = text .. '<sup><small><abbr title="Add Mandarin homophones (click on this if and only if you know what you are doing!)"><span class="plainlinks">="edit"})) .. ' +]</span></abbr></small></sup>'
end
text = text .. "\n*** <small>'']''</small>: "
local id = m_zh.ts_determ(mw.title.getCurrentTitle().text)
if id == 'trad' then
text = text .. '<span class="form-of pinyin-t-form-of transliteration-' .. m_zh.ts(mw.title.getCurrentTitle().text) .. '" lang="cmn">'
elseif id == 'simp' then
text = text .. '<span class="form-of pinyin-s-form-of transliteration-' .. m_zh.st(mw.title.getCurrentTitle().text) .. '" lang="cmn">'
elseif id == 'both' then
text = text .. '<span class="form-of pinyin-ts-form-of" lang="cmn">'
end
if py then
text = text .. '<code>' .. py .. '</code>'
else
text = text .. '<code>'
if cap then
text = text .. export.py_format(pinyin, true, true)
else
text = text .. export.py_format(pinyin, false, true)
end
if tl or tl2 or tl3 then
text = text .. ' → '
if tl then tl_pos = 1 elseif tl2 then tl_pos = 2 elseif tl3 then tl_pos = 3 end
if cap then
text = text .. export.make_tl(export.py_format(pinyin, true, false, true, true), tl_pos, true, true)
else
text = text .. export.make_tl(pinyin_simple_fmt_nolink, tl_pos, true)
end
end
text = text .. '</code>'
if tl then text = text .. ' <small>(toneless final syllable variant)</small>'
elseif tl2 or tl3 then text = text .. ' <small>(toneless variant)</small>' end
end
text = text .. "</span>\n*** <small>'']''</small>: " .. '<span lang="zh" class="Bopo">' .. export.py_zhuyin(pinyin_simple_fmt, true)
if tl or tl2 or tl3 then
text = text .. ' → ' .. export.py_zhuyin(export.make_tl(pinyin_simple_fmt_nolink, tl_pos, false), true)
end
text = text .. '</span>'
if tl then text = text .. ' <small>(toneless final syllable variant)</small>'
elseif tl2 or tl3 then text = text .. ' <small>(toneless variant)</small>' end
if len(mw.title.getCurrentTitle().text) == 1 then
text = text .. "\n*** <small>'']''</small>: <code>" .. export.py_wg(pinyin_simple_fmt) .. '</code>'
end
text = text .. "\n*** <small>'']''</small>: <code>"
if tl or tl2 or tl3 then
text = text .. export.py_gwoyeu(export.make_tl(pinyin_simple_fmt_nolink, tl_pos, false), pinyin_simple_fmt)
else
text = text .. export.py_gwoyeu(pinyin_simple_fmt)
end
text = text .. '</code>'
text = text .. '\n*** <small>] <sup>(])</sup></small>: <span class="IPA">/' .. export.py_ipa(pinyin)
if tl or tl2 or tl3 then
text = text .. '/ → /' .. export.py_ipa(export.make_tl(pinyin_simple_fmt_nolink, tl_pos, false))
end
text = text .. '/</span>'
if a then
if a == 'y' then a = 'zh-' .. pinyin_simple_fmt .. '.ogg' end
text = text .. '\n*** ]]'
end
if hom_found then
text = text .. '\n*** <small>Homophones</small>: <table class="wikitable" style="width:15em;margin:0; position:left; text-align:center"><tr><th class="mw-customtoggle-cmnhom" style="color:#3366bb"></th></tr><tr class="mw-collapsible mw-collapsed" id="mw-customcollapsible-cmnhom"><td><sup><div style="float: right; clear: right;"><span class="plainlinks">="edit"})) .. ' edit]</span></div></sup>' .. export.homophones(mw.ustring.lower(pinyin_simple_fmt)) .. '</td></tr></table>'
end
return text
end
function export.homophone_link(text)
text = text.args
detoned = gsub(export.py_transform(text, true), '', '')
detoned = gsub(detoned, ' +', ' ')
local p = split(detoned, " ")
outlink = ""
lastletter = ""
for i = 1, #p do
link = gsub(p, "()(*)", "%1#%1%2")
link = mw.ustring.gsub(link, "^%S", mw.ustring.upper)
link = "[[Annexe:Sinogrammes/Pinyin/"..link
apostrophe = ""
--if mw.ustring.find(lastletter..mw.ustring.sub(p,1,1),"") then
-- apostrophe = "’"
--end
lastletter = mw.ustring.sub(link,1,-1)
--link = mw.ustring.upper(mw.ustring.sub(p,1,1))
--link = "[[Annexe:Sinogrammes/Pinyin/"..link
outlink = outlink .. apostrophe .. link .. '|' .. export.py_number_to_mark(p) .. ']], '
end
return mw.ustring.sub(outlink,1,mw.ustring.len(outlink)-2)
end
return export