Module:Crh

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 isFalse(value)
	if value == "no" or value == "n" or value == "false" or value == "0" or value == "off" or value == "none" then
		return true
	else 
		return false
	end
end

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 isFalse(value) 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 label = args["label"]
    local labelOnly = parseBoolean(args["label-only"], true)

    local output = {}
    local parts = {}

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

	-- if label and not isFalse(label) then
 --   	table.insert(parts, label .. ":")
 --   elseif label and isFalse(label) then
 --   	do return end
 --   elseif 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 latinText then
		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
	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

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.