Module:User:ZxxZxxZ/IPA2

Hello, you have come here looking for the meaning of the word Module:User:ZxxZxxZ/IPA2. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:User:ZxxZxxZ/IPA2, but we will also tell you about its etymology, its characteristics and you will know how to say Module:User:ZxxZxxZ/IPA2 in singular and plural. Everything you need to know about the word Module:User:ZxxZxxZ/IPA2 you have here. The definition of the word Module:User:ZxxZxxZ/IPA2 will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:User:ZxxZxxZ/IPA2, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This is a private module sandbox of ZxxZxxZ, for his own experimentation. Items in this module may be added and removed at ZxxZxxZ's discretion; do not rely on this module's stability.


local export = {}

-- ]
function export.template_IPA(frame)
    local args = frame:getParent().args
    local langcode = args or 'en'
    local lang = require("Module:languages").getByCode(langcode)
    NAMESPACE = mw.title.getCurrentTitle().nsText

    ---- Initial link to pronunciation's guide page ----
    local ret = ']'

    -- TODO

    ret = ret .. ': '

    ---- Format the given pronunciation(s) ----
    if args == nil then
        error('No pronunciation given to the parameter #1')
    end

    local i = 1
    while args do
        if args == "" then
            error('No pronunciation given to the paramater #' .. i)
        end

        if i ~= 1 then
            ret = ret .. ','

            local note = args
            if note and note ~= '' then
            	ret = ret .. '<ref>' .. note .. '</ref>'
            end

            ret = ret .. ' '
        end

        ret = ret .. export.format_IPA(args, lang)

        i = i + 1
    end

    return ret
end

-- Takes an IPA pronunciation and formats it
function export.format_IPA(text, lang)
	if type(text) == "table" then
		local args = text:getParent().args
		text = args or error("IPA string has not been specified")
		lang = args
	end

    local categories = {}

    -- Fetch the representation type marks and remove them for "text2"
    local repr_mark = {}
    repr_mark.i, repr_mark.f, repr_mark.left, repr_mark.right = mw.ustring.find(text, '^(.).-(.)$')
    local text2 = mw.ustring.sub(text, 2, -2)

    -- Check for obsolete and nonstandard symbols
    local nonstandard = {
        "ɑ̢", "d̂", "t̂", "n̂", "l̂", "k̫", "ɔ̗", "ɔ̖", -- these symbols consist of more than one character, so we can't put them in the line below
        "",
    }

    for i, symbol in ipairs(nonstandard) do
        if mw.ustring.find(text2, symbol) then
            table.insert(categories, "IPA pronunciations with obsolete or nonstandard characters")
            break
        end
    end

    -- Check for invalid symbols
    local valid_symbols = '%(%)%%{%|%}.!abcdefhijklmnopqrstuvwxyz¡àáâãäæçèéêëìíîïðòóôõöøùúûüýÿāăēĕěħĩīĭŋōŏőœũūŭűŷǀǁǂǃǎǐǒǔǖǘǚǜǟǣǽǿȁȅȉȍȕȫȭȳɐɑɒɓɔɕɖɗɘəɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɪɫɬɭɮɯɰɱɲɳɴɵɶɸɹɺɻɽɾʀʁʂʃʄʈʉʊʋʌʍʎʏʐʑʒʔʕʘʙʛʜʝʟʡʢʬʭʰʱʲʳʴʵʶʷʸʼˀˁˈˌːˑ˞ˠˡˢˣ˥˦˧˨˩ˬ˭̘̙̜̝̞̟̠̣̤̥̩̪̬̯̰̹̺̻̼͇͈͉͍͎͔͕̀́̂̃̄̆̈̋̌̏̽͆͊͋͌̚͢͡βθχᴙᵊᵐᵑᵻᵿᶑᶣᶬᶮᶯᶰᶹ᷽᷄᷅᷆᷇᷈᷉ḁḛḭḯṍṏṳṵṹṻạẹẽịọụỳỵỹ‖․‥…‼‿ⁿ↑↓↗↘ⱱꜛꜜꟸꟹ𝆏𝆑'

    if mw.ustring.find(text2, '') then
    	table.insert(categories, "IPA pronunciations with invalid IPA characters")
    end

    -- Check the representation type
    if not ((repr_mark.left == '/' and repr_mark.right == '/')
    or      (repr_mark.left == '')) then
    	table.insert(categories, "IPA pronunciations with invalid representation marks")
    end

	-- link to rhymes page, if there is any
	--text = export.linkToRhyme(text, lang)

    -- Format the text
    text = '<span class="IPA" lang="">' .. text .. '</span>'

    -- Add the categories
    for key, cat in ipairs(categories) do
        text = text .. "]"
    end
 
    return text
end

-- Takes an IPA pronunciation and links to a rhyme, if there is any.
function export.linkToRhyme(text, lang)
	local rhyme
	local lang_name = lang:getCanonicalName()

	-- find possible rhymes and link to an existing one
	for i = 1, mw.ustring.len(text) do
		rhyme = mw.ustring.sub(text, i)
        rhyme = mw.ustring.gsub(rhyme, ']', '')

		if mw.title.new(lang_name .. ':-' .. rhyme, 'Rhymes').exists then
			text = mw.ustring.sub(text, 1, i - 1)
			    .. '[[Rhymes:' .. lang_name .. ':-' .. rhyme .. '|'
			    .. mw.ustring.sub(text, i)
			    .. ']]'

			break
		end
	end

    return text
end

return export