Jump to content

Module:Crh

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Primium (talk | contribs) at 23:17, 31 May 2024 (Created Crimean Tatar language module for {{crh}}). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

require('strict')

local p = {}

-- Errors
local error_msg = {
	
}

local err_category = {
	['crh'] = '[[Category:crh template errors]]'
}

local function errorMessage(error)
	return '<span class="error" style="font-size:100%">Error in crh template: {{' .. error .. '}}</span>'
	end

-- Helper function to parse boolean parameters
local function parseBoolean(value, default)
    if value == nil then
        return default
    elseif type(value) == "string" then
        value = value:lower()
        if value == "yes" or value == "y" or value == "true" or value == "1" or value == "on" then
            return true
        elseif value == "no" or value == "n" or value == "false" or value == "0" or value == "off" then
            return false
        end
    end
    return default
end

-- Helper function to get parameter value, considering aliases
local function getParamValue(params, paramName, aliases)
    local value = params[paramName]
    if value == nil and aliases then
        for _, alias in ipairs(aliases) do
            value = params[alias]
            if value then break end
        end
    end
    return value
end

-- Main function to render text
function p.renderText(frame)
    local args = require ('Module:Arguments').getArgs (frame);
    
    local latinText = args[1]
    local cyrillicText = args[2]
    local arabicText = args[3]
    local literalTranslation = getParamValue(args, "lit", {"literal", "literally"})
    local link = parseBoolean(args["link"], true)
    local lead = parseBoolean(args["lead"], true)
    local labelOnly = parseBoolean(args["label-only"], true)
    
    if not latinText or latinText == "" then
        return errorMessage("Latin text required")
    end

    local output = {}
    local parts = {}

    if lead and link then
        table.insert(output, "[[Crimean Tatar language|Crimean Tatar]]: ")
    elseif lead and not link then
		table.insert(output, "Crimean Tatar: ")
    end

    if lead and not labelOnly and link then
        table.insert(parts, "[[Latin alphabet|Latin]]: ''" .. latinText .. "''")
    elseif lead and not labelOnly and link then
        table.insert(parts, "Latin: ''" .. latinText .. "''")
    else
        table.insert(parts, "''" .. latinText .. "''")
    end

    if cyrillicText and not labelOnly and link then
        table.insert(parts, "[[Cyrillic script|Cyrillic]]: " .. cyrillicText)
    elseif cyrillicText and not labelOnly and not link then
        table.insert(parts, "Cyrillic: " .. cyrillicText)
    elseif cyrillicText and labelOnly then
        table.insert(parts, cyrillicText)
    end

    if arabicText and not labelOnly and link then
        table.insert(parts, "[[Arabic script|Arabic]]: " .. arabicText)
    elseif arabicText and not labelOnly and not link then
        table.insert(parts, "Arabic: " .. arabicText)
    elseif arabicText and labelOnly then
        table.insert(parts, arabicText)
    end

    if literalTranslation and link then
        table.insert(parts, "[[Literal translation|lit.]] '" .. literalTranslation .. "'")
    elseif literalTranslation and not link then
        table.insert(parts, "<abbr title=\"literal translation\">lit.</abbr> '" .. literalTranslation .. "'")
    end

    table.insert(output, table.concat(parts, ", "))

    return table.concat(output)
end

return p