Module:User:ZxxZxxZ/utilities

Hello, you have come here looking for the meaning of the word Module:User:ZxxZxxZ/utilities. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:User:ZxxZxxZ/utilities, but we will also tell you about its etymology, its characteristics and you will know how to say Module:User:ZxxZxxZ/utilities in singular and plural. Everything you need to know about the word Module:User:ZxxZxxZ/utilities you have here. The definition of the word Module:User:ZxxZxxZ/utilities will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:User:ZxxZxxZ/utilities, 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 languages = mw.loadData("Module:languages")
local export = {}
 
-- Create a tagged text from a given text. This is equivalent of the script templates.
function export.tag_text(text, lang, tag, class)
    if text then
        return "<" .. (tag or "span") .. (class and (" class=\"" .. class .. "\"") or "")
               .. " lang=\"" .. lang .. "\">" .. text .. "</" .. (tag or "span") .. ">"
    else
        return ""
    end
end
 
-- transliterate the text, if possible
function export.translit(lang, text)
    -- TODO: the table's information should be moved to ]
    local translit_modules = {
         = "Module:Avst-translit",
         = "Module:el-translit",
         = "Module:ru-translit",
         = "Module:ug-translit",
         = "Module:tg-translit",
         = "Module:ka-translit",  
         = "Module:xcl-translit",
         = "Module:axm-translit",
         = "Module:hy-translit"
    }
 
    if translit_modules then
        return require(translit_modules).tr(text)
    end
end
 
-- Detect the script based on the first alphabetical characters of a string
function export.detect_script(text, lang)
    -- list of characters that may occur at the beginning of a word
    local chars_table = {
         = "A-Za-z",
         = "؀-ۯ",
         = "Ա-֊",
         = "ঁ-৺",
         = "Ѐ-ӿ",
         = "ँ-ॽ",
         = "پچژکگی؀-۹",
         = "Ⴀ-ჼ",
         = "𐌰-𐍊",
         = "ʹ-Ͽ",
         = "א-ת",
         = "ក-៹",
         = "ກ-ໝ",
         = "᠀-ᢪ",
         = "က-ၙ", 
         = "ก-ฺ",        
         = "ං-෴",        
         = "ۈۇې",         --FIXME
        -- TODO
    }
 
    -- first try to detect the script based on the native scripts of the language
    local scripts = languages.scripts or {}
    for i, script in ipairs(scripts) do
        if chars_table and mw.ustring.match(text, "- .. "]") then
            return script
        end
    end
 
    -- not written in native scripts; check for all scripts
    for script, chars in ipairs(chars_table) do
        if mw.ustring.match(text, "-") then
            return script
        end
    end
end

function export.annotate(text, lang, tag, class, class_tr, translit, gloss, lit, gender, frame, pos)
    text = export.tag_text(text, lang, tag, class)

    local annotations = {}
    local paren_class = {}
    local mention = class_tr:find("mention") and true

    if translit then
        translit = translit:gsub('%%]', '') -- remove wikilinks

        table.insert(annotations, "<span lang=\"\"" .. (class_tr and (" class=\"" .. class_tr .. "\"") or "") .. ">" .. translit .. "</span>")
        if mention then
            table.insert(paren_class, "mention-tr-paren")
            if pos or gloss or lit then
                table.insert(paren_class, "mention-tr-gloss-paren")
            else
                table.insert(paren_class, "ib-brac")
                class_tr = "ib-content " .. class_tr
            end
        end
    else
        if mention and (pos or gloss or lit) then
            table.insert(paren_class, "mention-gloss-paren")
        end
    end

    if pos then
        table.insert(annotations,
                     mw.title.new("pos " .. pos, "Template").exists
                     and frame:expandTemplate{title = "pos " .. pos}
                     or pos)
    end

    if gloss then
        table.insert(annotations, "<span class=\"mention-gloss-double-quote\">“</span><span class='mention-gloss'>" .. gloss .. "</span><span class=\"mention-gloss-double-quote\">”</span>")
    end

    if lit then
        table.insert(annotations, "literally <span class=\"mention-gloss-double-quote\">“</span><span class='mention-gloss'>" .. lit .. "</span><span class=\"mention-gloss-double-quote\">”</span>")
    end

    if #annotations > 0 then
        text = text .. "&nbsp;"

        if #paren_class > 0 then
            text = text .. "<span class=\"" .. table.concat(paren_class, " ") .. "\">(</span>"
        else
            text = text .. "("
        end

        text = text .. table.concat(annotations, ", ")

        if #paren_class > 0 then
            text = text .. "<span class=\"" .. table.concat(paren_class, " ") .. "\">)</span>"
        else
            text = text .. ")"
        end
    end

    if gender then
        if gender or gender then
            -- {{#if:{{{g|{{{g1|}}}}}}|&nbsp;{{{{{g|{{{g1|}}}}}}|{{{g2|}}}|{{{g3|}}}}}}}
            text = text .. "&nbsp;" .. frame:expandTemplate{title = gender, args = {gender, gender}}
        elseif gender then
            local gen = require("Module:gender and number")
            text = text .. "&nbsp;" .. gen.format_list(gender)
        end
    end

    return text
end

return export