模組:用戶:Cedric tsan cantonais/沙盒/langues

來自維基辭典

呢個模組嘅解說可以喺模組:用戶:Cedric tsan cantonais/沙盒/langues/doc度開

b = require('模組:用戶:Cedric tsan cantonais/沙盒/bases')

local p = {}

-- 從本地清單[[Module:用戶:Cedric tsan cantonais/沙盒/langues/data]]獲取語言名
-- 本模組衹能夠通過其他模使用
function p.get_nom(code)
    -- 無輸入語言代碼就輸出「nil」.
    if (code == nil) then return nil end
    
    -- enlevés前後嘅空格
     code = mw.text.trim(code)
    
    -- Récupère la table des langues entière (en cache)
    local langues = mw.loadData('模組:用戶:Cedric tsan cantonais/沙盒/langues/data')
    
    -- 輸入嘅代碼有無對應嘅語言? A-t-on la langue correspondant au code donné ?
    if (langues[code] and langues[code]['nom']) then
        -- 攈到!輸出語言名。
        return langues[code]['nom']
    else
        -- 攈唔到。乜都唔輸出。
        return nil
    end
end

-- Fonction pouvant remplacer les appels de type {{ {{{lang}}} }} dans les modèles
-- Cette fonction marche pour un modèle
function p.nom_langue(frame)
    local args
    if frame.args ~= nil and frame.args[1] ~= nil then
        args = frame.args
    else
        args = frame:getParent().args
    end
    local code = args[1]
    
    local langue = p.get_nom(code)
    
    if (langue == nil or langue == '') then
        return '語言未知嘅'
    else
        return langue
    end
end

-- Fonction pour écrire le nom d'une langue dans une liste (or traductions)
-- Cette fonction marche pour un modèle {{L}}
function p.langue_pour_liste(frame)
    local args
    if frame.args ~= nil and frame.args[1] ~= nil then
        args = frame.args
    else
        args = frame:getParent().args
    end
    local code = args[1]
    
    -- 有無輸入到語言代碼?
    if code == nil or mw.text.trim(code) == '' then
        return "''未輸入語言代碼''" .. b.fait_categorie_contenu('維基辭典:缺少語言代碼')
    end
    
    code = mw.text.trim(code)
     
    local langue = p.get_nom(code)
    
    if (langue == nil or langue == '') then
        return code .. '*' .. b.fait_categorie_contenu('維基辭典:語言代碼唔確定')
    else
        return b.ucfirst(langue)
    end
end

-- 搜索同輸出通往對應語言嘅維基辭典嘅維基代碼(如果辭典存在)
function p.get_lien_Wikimedia(code)
    -- 無語言代碼?輸出「nil」。
    if (code == nil) then return nil end
    
    -- -- enlevés前後嘅空格
     code = mw.text.trim(code)
    
    -- 查詢語言一覽
    local langues = mw.loadData('模組:用戶:Cedric tsan cantonais/沙盒/langues/data')
    
    -- 輸入嘅代碼有無對應嘅語言? A-t-on la langue correspondant au code donné ?
    if (langues[code] and langues[code]['wmlien']) then
        -- 攈到!Renvoie le nom
        return langues[code]['wmlien']
    else
        -- 攈唔到。輸出「nil」。
        return nil
    end
end

function p.has_portail(code)
	-- Récupère la table des langues entière (en cache)
	local langues = mw.loadData('模組:用戶:Cedric tsan cantonais/沙盒/langues/data')

	if (langues[code] and langues[code]['portail']) then
		return true
	else
		return false
	end
end

return p