Jump to content

Module:Deranize: Difference between revisions

Only show word-initial o'aomo when necessary
m (test)
(Only show word-initial o'aomo when necessary)
Line 76: Line 76:
   ["*"] = " 󱛚",
   ["*"] = " 󱛚",
   ["_"] = "󱛛", -- compatibility nbsp
   ["_"] = "󱛛", -- compatibility nbsp
}
local vowel_lookalikes = {
  ["s"] = true,
  ["b"] = true,
  ["c"] = true,
  ["g"] = true,
  ["f"] = true,
}
local diphthong_lookalikes = {
  ["d"] = true,
  ["p"] = true,
  ["z"] = true,
  ["nh"] = true,
}
}


Line 86: Line 101:
   local len = mw.ustring.len(word)
   local len = mw.ustring.len(word)
   -- NB. this is not PCRE regex, see https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Ustring_patterns
   -- NB. this is not PCRE regex, see https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Ustring_patterns
   local toaqre = "()([mbpfndtzcsrljꝡgk']?h?)([auıoe])([̣]?)([́̈̂̀]?)([auıoe]?[auıoe]?)()([qm]?)([-·]?)()([auıoe]?)"
   local toaqre = "()([mbpfndtzcsrljꝡgk']?h?)([auıoe])([̣]?)([́̈̂̀]?)([auıoe]?[auıoe]?)()([qm]?)([-·]?)()([mbpfndtzcsrljꝡgk']?h?)([auıoe]?)"
   local is_first_syllable = true
   local is_first_syllable = true
   while ix <= len do
   while ix <= len do
     local shouldbreak = false
     local shouldbreak = false
     local pos_init, initial, medial, underdot, diacritic, final, pos_precoda, coda, hyphen, pos_postcoda, lingering_vowel = mw.ustring.match(word, toaqre, ix)
     local pos_init, initial, medial, underdot, diacritic, final, pos_precoda, coda, hyphen, pos_postcoda, next_initial, next_medial = mw.ustring.match(word, toaqre, ix)
     if pos_init == nil then
     if pos_init == nil then
       break
       break
     end
     end
     res[#res+1] = u.toNFC(u.sub(word, ix, pos_init - 1))
     res[#res+1] = u.toNFC(u.sub(word, ix, pos_init - 1))
     if coda == "m" and lingering_vowel ~= "" then
     if coda == "m" and next_initial == "" and next_medial ~= "" then
       coda = ""
       coda = ""
      next_initial = "m"
       ix = pos_precoda
       ix = pos_precoda
     else
     else
Line 106: Line 122:
     if is_diphthong and reform then medial, final = v, "" end
     if is_diphthong and reform then medial, final = v, "" end
     local glyphs = {initial, tone, medial}
     local glyphs = {initial, tone, medial}
     if initial == "" and is_first_syllable then glyphs[1] = "'" end
     if initial == ""
      and is_first_syllable
      and (final == "" or (reform and is_diphthong))
      and coda == ""
      and (vowel_lookalikes[next_initial] or (reform and diphthong_lookalikes[next_initial])) then
      glyphs[1] = "'"
    end
     if not is_first_syllable then glyphs[2] = "" end
     if not is_first_syllable then glyphs[2] = "" end
     if glyphs[1] == "'" or glyphs[1] == "ꝡ" then
     if glyphs[1] == "'" or glyphs[1] == "ꝡ" then