Jump to content

Module:Crh: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
added Arabic script formatting
HTML `lang` and `title`
Line 64: Line 64:
end
end


local spannedLatin = "<span title=\"Crimean Tatar-language text\" lang=\"crh-Latn\">" .. latinText .. "</span>"
if lead and not labelOnly and link then
if lead and not labelOnly and link then
table.insert(parts, "[[Latin alphabet|Latin]]: ''" .. latinText .. "''")
table.insert(parts, "[[Latin alphabet|Latin]]: ''" .. spannedLatin .. "''")
elseif lead and not labelOnly and link then
elseif lead and not labelOnly and link then
table.insert(parts, "Latin: ''" .. latinText .. "''")
table.insert(parts, "Latin: ''" .. spannedLatin .. "''")
else
else
table.insert(parts, "''" .. latinText .. "''")
table.insert(parts, "''" .. spannedLatin .. "''")
end
end


if cyrillicText and not labelOnly and link then
if cyrillicText then
local spannedCyrillic = "<span title=\"Crimean Tatar-language text\" lang=\"crh-Cyrl\">" .. cyrillicText .. "</span>"
table.insert(parts, "[[Cyrillic script|Cyrillic]]: " .. cyrillicText)
elseif cyrillicText and not labelOnly and not link then
if not labelOnly and link then
table.insert(parts, "Cyrillic: " .. cyrillicText)
table.insert(parts, "[[Cyrillic script|Cyrillic]]: " .. spannedCyrillic)
elseif cyrillicText and labelOnly then
elseif cyrillicText and not labelOnly and not link then
table.insert(parts, cyrillicText)
table.insert(parts, "Cyrillic: " .. spannedCyrillic)
elseif cyrillicText and labelOnly then
end
table.insert(parts, spannedCyrillic)
end
end
if arabicText then
if arabicText then
local formattedArabic = "<span lang=\"crh-Arab\" dir=\"rtl\">" .. arabicText .. "</span>"
local spannedArabic = "<span title=\"Crimean Tatar-language text\" lang=\"crh-Arab\" dir=\"rtl\">" .. arabicText .. "</span>"


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

Revision as of 23:43, 31 May 2024

require('strict')

local p = {}

-- Errors
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

	local spannedLatin = "<span title=\"Crimean Tatar-language text\" lang=\"crh-Latn\">" .. latinText .. "</span>"
    if lead and not labelOnly and link then
        table.insert(parts, "[[Latin alphabet|Latin]]: ''" .. spannedLatin .. "''")
    elseif lead and not labelOnly and link then
        table.insert(parts, "Latin: ''" .. spannedLatin .. "''")
    else
        table.insert(parts, "''" .. spannedLatin .. "''")
    end

    if cyrillicText then
    	local spannedCyrillic = "<span title=\"Crimean Tatar-language text\" lang=\"crh-Cyrl\">" .. cyrillicText .. "</span>"
	    if not labelOnly and link then
	        table.insert(parts, "[[Cyrillic script|Cyrillic]]: " .. spannedCyrillic)
	    elseif cyrillicText and not labelOnly and not link then
	        table.insert(parts, "Cyrillic: " .. spannedCyrillic)
	    elseif cyrillicText and labelOnly then
	        table.insert(parts, spannedCyrillic)
	    end
	end
    
    if arabicText then
    	local spannedArabic = "<span title=\"Crimean Tatar-language text\" lang=\"crh-Arab\" dir=\"rtl\">" .. arabicText .. "</span>"

	    if not labelOnly and link then
	        table.insert(parts, "[[Arabic script|Arabic]]: " .. spannedArabic)
	    elseif not labelOnly and not link then
	        table.insert(parts, "Arabic: " .. spannedArabic)
	    elseif labelOnly then
	        table.insert(parts, spannedArabic)
	    end
	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