Module:cmn-pron

Bonjour, vous êtes venu ici pour chercher la signification du mot Module:cmn-pron. Dans DICTIOUS, vous trouverez non seulement toutes les significations du dictionnaire pour le mot Module:cmn-pron, mais vous apprendrez également son étymologie, ses caractéristiques et comment dire Module:cmn-pron au singulier et au pluriel. Tout ce que vous devez savoir sur le mot Module:cmn-pron est ici. La définition du mot Module:cmn-pron vous aidera à être plus précis et correct lorsque vous parlerez ou écrirez vos textes. Connaître la définition deModule:cmn-pron, ainsi que celles d'autres mots, enrichit votre vocabulaire et vous fournit des ressources linguistiques plus nombreuses et de meilleure qualité.

 Documentation[voir] [modifier] [historique] [purger]

Ce module regroupe des fonctions pour transcrire du pinyin . Il a été importé du wiktionnaire anglophone. Il a besoin de Module:zh pour fonctionner.

Fonctions activées sur les modèles
Fonctions appelables depuis le wikicode
  • {{#invoke:cmn-pron|py_ipa|PINYIN}} : retourne une chaîne correspondant au pinyin retranscrit en alphabet phonétique international.
  • {{#invoke:cmn-pron|py_efeo|PINYIN}} : retourne une chaîne correspondant au pinyin retranscrit avec le système EFEO.
  • {{#invoke:cmn-pron|py_yale|PINYIN}} : retourne une chaîne correspondant au pinyin retranscrit avec le système Yale.
  • {{#invoke:cmn-pron|py_zhuyin|PINYIN}} : retourne une chaîne correspondant au pinyin retranscrit avec du zhuyin.

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 gsplit = mw.text.gsplit

local m_zh = require("Module:zh")
local _m_zh_data
local hom_data = mw.loadData("Module:zh/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
      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"
  }

  local wg_tones = {
     = '¹',  = '²',  = '³',  = '⁴',  = '⁵'
  }

  if type(text) == 'table' then text = text.args end
  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 t, replace in pairs(py_wg_final) do
        final = gsub(final, t, replace)
      end
      local untoned = (py_wg_initial or initial) .. final
      for t, replace in pairs(py_wg_syl) do
        untoned = gsub(untoned, t, replace)
      end
      untoned = gsub(untoned, "k(’?)ui", "k%1uei")
      return untoned .. wg_tones 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
  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 t, replace in pairs(py_yale_final) do
        final = gsub(final, t, replace)
      end
      local untoned = (py_yale_initial or initial) .. final
      for t, replace in pairs(py_yale_syl) do
        untoned = gsub(untoned, t, 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",
     = "tseu",
     = "ts'eu",
     = "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
  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, _)
      for t, replace in pairs(py_efeo_final) do
        final = gsub(final, t, replace)
      end
      local untoned = (py_efeo_initial or initial) .. final
      for t, replace in pairs(py_efeo_syl) do
        untoned = gsub(untoned, t, replace)
      end
      for t, replace in pairs(py_efeo_cleanup) do
        untoned = gsub(untoned, t, replace)
      end
      untoned = gsub(untoned, "k('?)ui", "k%1uei")
      return untoned end)
  end
  return table.concat(p, "-")
end

function export.py_wg(text)
	local py_wg_initial = {
		 = "p",  = "pʻ", 
		 = "t",  = "tʻ", 
		 = "k",  = "kʻ", 
		 = "ch",  = "chʻ",  = "hs", 
		 = "ts",  = "tsʻ",  = "j", 
		 = "ch",  = "chʻ", 
	}
	
	local py_wg_final = {
		?)e()"] = "%1ê%2", 
		 = "ê", 
		)an$"] = "%1en", 
		 = "%1ung", 
		)e$"] = "%1eh", 
		e"] = "üeh", 
		 = "rh", 
		 = "eh", 
		 = "i", 
		 = "i", 
	}
	
	local py_wg_syl = {
		 = "%1o", 
		h?ʻ?)uo"] = "%1o",
		 = "shih",  = "jih",
		 = "tzŭ",  = "tzʻŭ",  = "ssŭ", 
		?ʻ?)ê$"] = "%1o", 
		 = "yen", 
		 = "yu",  = "i",
		 = "k%1uei"
	}
	
	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)
	
	local function process_syllable(initial, final, tone)
		for text, replace in pairs(py_wg_final) do
			final = gsub(final, text, replace)
		end
		if (initial == "zh" or initial == "ch") and final == "i" then
			final = "ih"
		end
		local untoned = (py_wg_initial or initial) .. final
		for text, replace in pairs(py_wg_syl) do
			untoned = gsub(untoned, text, replace)
		end
		return untoned .. '<sup>' .. tone .. '</sup>'
	end

	for i = 1, #p do
		p = gsub(p, '^(?h?)(.+)()$', process_syllable)
	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', 
		 = 'io',
		--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 find(syllable, '^+$') then
				local current = sub(mw.title.getCurrentTitle().text, count, count)
				if find(current, '^$') then
					local exceptions = { = 'i',  = 'chi',  = 'ba',  = 'bu'}
					syllables = exceptions
				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 = export.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 = gsub(detone, '(+)', '%1r')
							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('') then replace = detone:gsub('', '%1%1', 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_tongyong(text)
	if type(text) == 'table' then text = text.args end
	
	local ty_tone = {
		 = "",  = "\204\129",  = "\204\140",  = "\204\128",  = "\204\138"
	}
	
	local function num_to_mark(syllable, tone)
		tone = ty_tone
		if tone ~= "" then
			if syllable:find('') then
				syllable = syllable:gsub("()", "%1" .. tone)
			elseif syllable:find('o') then
				syllable = syllable:gsub("(o)", "%1" .. tone)
			elseif syllable:find('') then
				syllable = syllable:gsub("()", "%1" .. tone)
			end
		end
		return syllable
	end
	
	local words = {}
	for word in gsplit(text, " ") do
		local cap = word:find("^")
		word = export.py_transform(word, true)
		local syllables = {}
		for syllable in gsplit(word, " ") do
			syllable = syllable:gsub("(h?)i", "%1ih")
			syllable = syllable:gsub("ü", "yu")
			syllable = syllable:gsub("()u", "%1yu")
			syllable = syllable:gsub("iu", "iou")
			syllable = syllable:gsub("ui", "uei")
			syllable = syllable:gsub("()eng", "%1ong")
			syllable = syllable:gsub("wen", "wun")
			syllable = syllable:gsub("iong", "yong")
			syllable = syllable:gsub("^zh", "jh")
			syllable = syllable:gsub("^q", "c")
			syllable = syllable:gsub("^x", "s")
			syllable = #syllables ~= 0 and syllable:gsub("^()", "'%1") or syllable
			syllable = syllable:gsub("^(+)()$", num_to_mark)
			
			table.insert(syllables, syllable)
		end
		word = table.concat(syllables, "")
		word = cap and word:gsub("^.", string.upper) or word
		table.insert(words, word)
	end
	
	return mw.ustring.toNFC(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
	text = gsub(text, "#", "")
	phon = gsub(phon, "#", "")
	
	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 "Mandarin standard"
	tag = (second ~= '') and second or "Mandarin standard"
	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, 'Mandarin standard', "]")
	text = gsub(text, 'Continent', "]")
	text = gsub(text, 'Taïwan', "]")
	text = gsub(text, 'Pékin', "]")
	text = gsub(text, 'erhua', "]")
	text = gsub(text, 'Minnan', "]")
	text = gsub(text, 'shangkouzi', "'']''")
	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 = {}

  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.homophone_link(text)
  text = text.args
  if text == "" then
    return ""
  end
  local detoned = gsub(export.py_transform(text, true), '', '')
  detoned = gsub(detoned, ' +', ' ')
  local p = split(detoned, " ")
  local outlink = ""
  for i = 1, #p do
    local link = gsub(p, "()(*)", "%1#%1%2")
    link = mw.ustring.gsub(link, "^%S", mw.ustring.upper)
    link = "[[Annexe:Sinogrammes/Pinyin/".. link
    outlink = outlink .. link .. '|' .. export.py_number_to_mark(p) .. ']], '
  end
  return mw.ustring.sub(outlink,1,mw.ustring.len(outlink)-2)
end



local function erhua(word, erhua_pos, pagename)
	local title = split(pagename, '')
	local linked_title = ''
	local syllables = split(export.py_transform(word), ' ')
	local count = #syllables
	erhua_pos = find(erhua_pos, '') and split(erhua_pos, ';') or { count }
	for _, pos in ipairs(erhua_pos) do
		pos = tonumber(pos)
		title = title .. '兒'
		syllables = syllables .. 'r'
	end
	local title = table.concat(title)
	if mw.title.new(title).exists then
		linked_title = ' (' .. m_zh.link(nil, nil, {title, tr='-'}) .. ')'
	end
	for i, syllable in pairs(syllables) do
		if i ~= 1 and mw.ustring.toNFD(syllable):find('^') then
			syllables = "'" .. syllable
		end
	end
	word = table.concat(syllables, '')
	return (export.tag('', '', 'erhua-ed') .. linked_title), word
end

export.erhua = erhua

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, '')
		table.insert(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)
			table.insert(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, '')
		table.insert(text, export.make_table(title, pinyin, (args or ''), (args or ''), (args or ''), (args or ''), (args or ''), (args or args or ''), true))
		table.insert(text, ', 1, '') or args) .. ']]')
		
		if args and args ~= '' then
			title, pinyin = erhua(pinyin, args, pagename)
			table.insert(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
			table.insert(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)
				table.insert(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
				table.insert(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)
					table.insert(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
					table.insert(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)
						table.insert(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
		table.insert(text, ', 1, '') .. ']]')
	end
	return table.concat(text)
end

function export.make_audio(args)
	local text, reading, pinyin = {}, {}, ""
	local audio = {
		args or args or '',
		args or args or '',
		args or args or '',
		args or args or '',
		args or args or '',
	}
	for i=1,5 do
		reading = args or ''
		if i == 1 then
			pinyin = export.straitdiff(reading, 1, '')
		else
			pinyin = (reading ~= '') and reading or export.straitdiff(reading, i, '')
		end
		pinyin = export.py_format(pinyin, false, false, true)
		add_audio(text, audio, pinyin)
	end
	return table.concat(text)
end

function add_audio(text, audio, pinyin)
	if audio and audio ~= "" then
		if audio == "y" then audio = string.format('zh-%s.ogg', pinyin) end
		table.insert(text, '\n*:: [[File:')
		table.insert(text, audio)
		table.insert(text, ']]')
		table.insert(text, ']')
	end
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
		table.insert(text, '* ]')
	else
		table.insert(text, '<br>')
	end
	table.insert(text, '\n** <small>' .. title .. '</small>')
	local hom_found
	if hom_data.list then
		hom_found = true
	else
		hom_found = false
		table.insert(text, '<sup><small><abbr title="Ajouter des homophones en mandarin"><span class="plainlinks">="edit"})) .. ' +]</span></abbr></small></sup>')
	end
	table.insert(text, "\n*** <small>'']''</small>: ")
	local id = m_zh.ts_determ(mw.title.getCurrentTitle().text)
	if id == 'trad' then
		table.insert(text, '<span class="form-of pinyin-t-form-of transliteration-')
		table.insert(text, m_zh.ts(mw.title.getCurrentTitle().text))
	elseif id == 'simp' then
		table.insert(text, '<span class="form-of pinyin-s-form-of transliteration-')
		table.insert(text, m_zh.st(mw.title.getCurrentTitle().text))
	else -- both
		table.insert(text, '<span class="form-of pinyin-ts-form-of')
	end
	table.insert(text, '" lang="cmn" style="font-family: monospace;">')
	if py then
		table.insert(text, py)
	else
		if cap then
			table.insert(text, export.py_format(pinyin, true, true))
		else
			table.insert(text, export.py_format(pinyin, false, true))
		end
		if tl or tl2 or tl3 then
			table.insert(text, ' → ')
			if tl then tl_pos = 1 elseif tl2 then tl_pos = 2 elseif tl3 then tl_pos = 3 end
			if cap then
				table.insert(text, export.make_tl(export.py_format(pinyin, true, false, true, true), tl_pos, true, true))
			else
				table.insert(text, export.make_tl(pinyin_simple_fmt_nolink, tl_pos, true))
			end
		end
		if tl then table.insert(text, ' <small>(toneless final syllable variant)</small>')
			elseif tl2 or tl3 then table.insert(text, ' <small>(toneless variant)</small>') end
	end
	table.insert(text, "</span>\n*** <small>'']''</small>: ")
	table.insert(text, '<span lang="zh-Bopo" class="Bopo">')
	table.insert(text, export.py_zhuyin(pinyin_simple_fmt, true))
	if tl or tl2 or tl3 then
		table.insert(text, ' → ')
		table.insert(text, export.py_zhuyin(export.make_tl(pinyin_simple_fmt_nolink, tl_pos, false), true))
	end
	table.insert(text, '</span>')
	if tl then table.insert(text, ' <small>(toneless final syllable variant)</small>')
		elseif tl2 or tl3 then table.insert(text, ' <small>(toneless variant)</small>') end
	if len(mw.title.getCurrentTitle().text) == 1 then
		table.insert(text, "\n*** <small>'']''</small>: <code>")
		table.insert(text, export.py_wg(pinyin_simple_fmt))
		table.insert(text, '</code>')
	end
	table.insert(text, "\n*** <small>'']''</small>: <code>")
	if tl or tl2 or tl3 then
		table.insert(text, export.py_gwoyeu(export.make_tl(pinyin_simple_fmt_nolink, tl_pos, false), pinyin_simple_fmt))
	else
		table.insert(text, export.py_gwoyeu(pinyin_simple_fmt))
	end
	table.insert(text, '</code>')
	table.insert(text, "\n*** <small>'']''</small>: <code>")
	if tl or tl2 or tl3 then
		table.insert(text, export.py_tongyong(export.make_tl(pinyin_simple_fmt_nolink, tl_pos, false), pinyin_simple_fmt))
	else
		table.insert(text, export.py_tongyong(pinyin_simple_fmt))
	end
	table.insert(text, '</code>')
	table.insert(text, '\n*** <small>Sinological ] <sup>(])</sup></small>: <span class="IPA">/')
	table.insert(text, export.py_ipa(pinyin))
	if tl or tl2 or tl3 then
		table.insert(text, '/ → /')
		table.insert(text, export.py_ipa(export.make_tl(pinyin_simple_fmt_nolink, tl_pos, false)))
	end
	table.insert(text, '/</span>')
	-- if a then
	-- 	if a == 'y' then a = 'zh-' .. pinyin_simple_fmt .. '.ogg' end
	-- 	table.insert(text, '\n*** <div style="display:inline-block; position:relative; top:0.5em;">[[File:')
	-- 	table.insert(text, a)
	-- 	table.insert(text, ']]</div>]')
	-- end
	if hom_found then
		table.insert(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">[')
		table.insert(text, tostring(mw.uri.fullUrl("Module:zh/data/cmn-hom", {="edit"})))
		table.insert(text, ' edit]</span></div></sup>')
		table.insert(text, export.homophones(mw.ustring.lower(pinyin_simple_fmt)))
		table.insert(text, '</td></tr></table>')
	end
	return table.concat(text)
end

return export