This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

-- {{#invoke:IPAc|main|'w3rd}} > <span title = "/ˈ/ primary stress follows">ˈ</span><span title = "'w' in 'wind' ">w</span><span title = "/ɜr/ 'ir' in 'bird' ">ɜr</span><span title = "'d' in 'dye' ">d</span>
-- This module has not been heavily tested

local p = {}

function p.main( frame )
    local result = ""
    
    local a = frame.args[ 1 ]
    
    if type( a ) ~= "string" then error( "Must be a string" ) end
    
    local db = {
[{"b"}] = "'b' in 'buy' \">b",
[{"d"}] = "'d' in 'dye' \">d",
[{"ᵈ","(d)"}] = "optional 'd' \">ᵈ",
[{"dj","dy","dʲ"}] = "/dj/ 'd' in 'dew' \">dj",
[{"ð","D","dh"}] = "/ð/ 'th' in 'thy' \">ð",
[{"dʒ","J","dZ","dzh","ʤ"}] = "/dʒ/ 'j' in 'jam' \">dʒ",
[{"f"}] = "'f' in 'find'  \">f",
[{"ɡ","g"}] = "'g' in 'guy' \">ɡ",
[{"h"}] = "'h' in 'hi' \">h",
[{"j","y"}] = "/j/ 'y' in 'yes' \">j",
[{"k"}] = "'k' in 'kind' \">k",
[{"l","ɫ"}] = "'l' in 'lie' \">l",
[{"lj","ly","lʲ"}] = "/lj/ 'l' in 'lute' \">lj",
[{"m"}] = "'m' in 'my' \">m",
[{"n"}] = "'n' in 'nigh' \">n",
[{"nj","ny","nʲ"}] = "/nj/ 'n' in 'new' \">nj",
[{"ŋ","N","ng"}] = "/ŋ/ 'ng' in 'sing' \">ŋ",
[{"ŋg","ngg","Ng"}] = "/ŋɡ/ 'ng' in 'finger' \">ŋɡ",
[{"θ","T","th"}] = "/θ/ 'th' in 'thigh' \">θ",
[{"θj","thy","thj","θʲ"}] = "/θj/ 'th' in 'enthusiasm' \">θj",
[{"p"}] = "'p' in 'pie' \">p",
[{"r","ɹ","ɻ"}] = "'r' in 'rye' \">r",
[{"s"}] = "'s' in 'sigh' \">s",
[{"sj","sy","sʲ"}] = "/sj/ 's' in 'suit' \">sj",
[{"ʃ","S","sh"}] = "/ʃ/ 'sh' in 'shy' \">ʃ",
[{"t"}] = "'t' in 'tie' \">t",
[{"ᵗ","(t)"}] = "optional 't' \">ᵗ",
[{"tj","ty","tʲ"}] = "/tj/ 't' in 'tune' \">tj",
[{"tʃ","C","ch","tS","ʧ"}] = "/tʃ/ 'ch' in 'china' \">tʃ",
[{"v"}] = "'v' in 'vie' \">v",
[{"w"}] = "'w' in 'wind' \">w",
[{"hw","ʍ","wh"}] = "/hw/ 'wh' in 'why' \">hw",
[{"z"}] = "'z' in 'Zion' \">z",
[{"zj","zy","zʲ"}] = "/zj/ 'z' in 'Zeus' \">zj",
[{"ʒ","Z","zh"}] = "/ʒ/ 's' in 'pleasure' \">ʒ",
[{"x","kh"}] = "/x/ 'ch' in 'loch' \">x",
[{"ʔ","?"}] = "/ʔ/ the catch in 'uh-oh' \">ʔ",
[{"ɑː","A:","a:","aː","ah","aa","ɑ:","ä","â"}] = "/ɑː/ 'a' in 'father' \">ɑː",
[{"ɑr","ar","ɑɹ","är","âr","aːr","a:r","ɑ:r","ɑːr"}] = "/ɑr/ 'ar' in 'bard' \">ɑr",
[{"ɒ","Q","ŏ"}] = "/ɒ/ short 'o' in 'body' \">ɒ",
[{"ɒ̃","ɑ̃","ɒ~","ɑ~","ã","a~","Q~"}] = "/ɒ̃/ nasal 'an' in 'vin blanc' \">ɒ̃",
[{"ɒr","ŏr","Qr"}] = "/ɒr/ 'or' in 'moral' \">ɒr",
[{"æ","ae","&","{","}","ă"}] = "/æ/ short 'a' in 'bad' \">æ",
[{"aɪ","ai","aI","ye","eye","ī"}] = "/aɪ/ long 'i' in 'bide' \">aɪ",
[{"aɪər","aɪr","aIr","īr","aɪə","yr"}] = "/aɪər/ 'ire' in 'fire' \">aɪər",
[{"aʊ","au","aU","ow"}] = "/aʊ/ 'ou' in 'pout' \">aʊ",
[{"aʊər","aʊr","aUr","aʊə","aur"}] = "/aʊər/ 'our' in 'hour' \">aʊər",
[{"ɛ","E","ĕ"}] = "/ɛ/ short 'e' in 'bed' \">ɛ",
[{"ɛr","Er","ĕr","err"}] = "/ɛr/ 'err' in 'merry' \">ɛr",
[{"eɪ","ei","eI","ay","ā","eː","e:"}] = "/eɪ/ long 'a' in 'base' \">eɪ",
[{"ær","aer","&r","æɹ","ăr","arr"}] = "/ær/ 'arr' in 'marry' \">ær",
[{"ɛər","eir","eIr","e@r","E@r","air","ɛɪɹ","eɪr","eːr","e:r","ɛəɹ","ār","ɛə"}] = "/ɛər/ 'are' in 'bare' \">ɛər",
[{"ɪ","I","ĭ"}] = "/ɪ/ short 'i' in 'bid' \">ɪ",
[{"ɪr","ĭr","irr"}] = "/ɪr/ 'irr' in 'mirror' \">ɪr",
[{"iː","i:","ee","ē"}] = "/iː/ long 'e' in 'bead' \">iː",
[{"ɪər","i:r","iːr","I@r","i@r","eer","ɪəɹ","iːɹ","ēr","ɪə"}] = "/ɪər/ 'ear' in 'beard' \">ɪər",
[{"ⁱ","(i)","(ɪ)"}] = "/ⁱ/ optional 'i' in 'nasturtium' \">ⁱ",
[{"ᵊ","(ə)","(@)"}] = "/ᵊ/ optional 'ə' in 'jewelry' \">ᵊ",
[{"ʲ","(j)","(y)","ʸ"}] = "/ʲ/ optional 'j' in 'Lucas' \">ʲ",
[{"ɔː","O","O:","aw","ɔ:","ô"}] = "/ɔː/ 'au' in 'fraud' \">ɔː",
[{"ɔr","Or","awr","ɔɹ","ôr","ɔ(r)"}] = "/ɔr/ 'or' in 'born' \">ɔr",
[{"ɔɪ","oj","ɔj","oi","oɪ","ɔi","OI","oy"}] = "/ɔɪ/ 'oy' in 'boy' \">ɔɪ",
[{"ɔɪər","ɔɪr","oyr","ɔɪə"}] = "/ɔɪər/ 'oir' in 'loir' (rare) \">ɔɪər",
[{"oʊ","o:","oː","ou","oU","@u","@U","oh","oe","əʊ","əu","ɔʊ","ɔu","ō"}] = "/oʊ/ long 'o' in 'bode' \">oʊ",
[{"ɔər","oUr","ohr","ɔəɹ","ɔʊɹ","oʊɹ","oʊr","oːr","o:r","ōr","ɔə","ɔə(r)"}] = "/ɔər/ 'ore' in 'bore' \">ɔər",
[{"ʊ","U","uu","ŏŏ"}] = "/ʊ/ short 'oo' in 'foot' \">ʊ",
[{"ʊr","uur","Ur","ŏŏr"}] = "/ʊr/ 'our' in 'courier' \">ʊr",
[{"uː","u:","oo","ōō"}] = "/uː/ long 'oo' in 'food' \">uː",
[{"ʊər","u:r","uːr","u@r","U@r","oor","ʊəɹ","ōōr","ʊə"}] = "/ʊər/ 'our' in 'tour'  \">ʊər",
[{"juː","ju:","yu:","yew","ew","ū","yoo"}] = "/juː/ long 'u' in 'cute' \">juː",
[{"jʊər","ūr","yoor","ju:r","juːr","jʊə"}] = "/jʊər/ 'ure' in 'cure' \">jʊər",
[{"ʌ","V","ŭ"}] = "/ʌ/ short 'u' in 'bud' \">ʌ",
[{"ʌr","urr","Vr","ʌɹ","ŭr"}] = "/ʌr/ 'urr' in 'hurry' \">ʌr",
[{"ɜr","3","3:","ɝː","ɝ","ɜː","ɜ:","ɜ","3r","3:r","@:r","@:","ɜɹ","ûr","ɜ(r)"}] = "/ɜr/ 'ir' in 'bird' \">ɜr",
[{"ə","schwa","@"}] = "/ə/ 'a' in 'about' \">ə",
[{"ər","ɚ","@r","əɹ","ə(r)"}] = "/ər/ 'er' in 'finger' \">ər",
[{"ən","@n","ᵊn","n̩"}] = "/ən/ 'on' in 'button' \">ən",
[{"ɵ","<s>o</s>","o-","ou-","oʊ-"}] = "/ɵ/ variable 1st 'o' in 'omission' \">ɵ", --ambiguous example
[{"əm","@m","ᵊm","m̩"}] = "/əm/ 'm' in 'rhythm' \">əm",
[{"ɨ","<s>ɪ</s>","i-","I-","ɪ-"}] = "/ɨ/ 'e' in 'roses' \">ɨ",
[{"ʉ","<s>ʊ</s>","u-","U-","ʊ-"}] = "/ʉ/ variable 2nd 'u' in 'beautiful' \">ʉ", --ambiguous example
[{"jʉ","j<s>ʊ</s>","y<s>ʊ</s>","ju-","yu-","jU-","yU-","jʊ-"}] = "/jʉ/ variable 2nd 'u' in 'curriculum' \">jʉ", --ambigious example
[{"əl","@l","ᵊl","əɫ","l̩"}] = "/əl/ 'le' in 'bottle' \">əl",
[{"i"}] = "/i/ 'y' in 'happy' \">i",
[{"ˈ","'"}] = "/ˈ/ primary stress follows\">ˈ",
[{"ˌ",","}] = "/ˌ/ secondary stress follows\">ˌ",
[{".","·"}] = "/./ syllable break \">.",
[{"-","–"}] = "/-/ affix \">-",
-- [{",_"=, ]]
[{"_"}] = "Representation in the International Phonetic Alphabet (IPA) \"> ",
[{" and "}] = "\">/ & /", -- this is useful for "and" in place names, which is highly variable and not important to transcribe
[{"..."}]= "\">..." --this is useful for other highly variable words in place names, which are not important to transcribe

    }
    
    while mw.ustring.len( a ) > 0 do
        local fl, fv = 0, nil
        for t, i in pairs( db ) do 
            --mw.log( i, t )
            for tt, ii in pairs( t ) do
                --mw.log( tt, ii )
                if mw.ustring.find( a, ii, 1, true ) == 1 and mw.ustring.len( ii ) > fl then
                    fl = mw.ustring.len( ii )
                    fv = i
                end
            end
        end
        if fv == nil then
            fl, fv = 1, mw.ustring.sub( a, 1, 1 )
        else
            fv = "<span title = \"" .. fv .. "</span>"
        end
        result = result .. fv
        --mw.log( fl, fv, a )
        a = mw.ustring.sub( a, fl + 1 )
    end
        
    return result
end

return p