A modult a Modul:tryWDIDbyLang/doc lapon tudod dokumentálni

local p = {}

function guessLanguage()
	local text = mw.title.getCurrentTitle().text
    -- Define character sets for different languages
    local languages = {
        {"en", "[a-zA-Z]"},
        {"es", "[a-zA-ZñÑáéíóúüÁÉÍÓÚÜ]"},
        {"fr", "[a-zA-ZàâçéèêëîïôûùüÿñæœÀÂÇÉÈÊËÎÏÔÛÙÜŸŒ]"},
        {"de", "[a-zA-ZäöüÄÖÜß]"},
        {"ru", "[а-яА-ЯёЁ]"},
        {"uk", "[а-щА-ЩЬьЮюЯяЇїІіЄєҐґ]"},
        {"hu", "[a-zA-ZáéíóöőúüűÁÉÍÓÖŐÚÜŰ]"},
        {"ar", "[آأإابتثجحخدذرزسشصضطظعغفقكلمنهوية]"}
       
        -- Add more languages and their respective character sets as needed
    }

    -- Check the text against each language's character set
    for _, lang in ipairs(languages) do
        local guessedLanguage, charset = lang[1], lang[2]
        local matched = true
        for char in text:gmatch(".") do
            if not char:match(charset) then
                matched = false
                break
            end
        end
        if matched then
            return guessedLanguage
        end
    end

    -- If no language matches, return "Unknown"
    return nil
end

function p.getWikidataId()
    local title = mw.title.getCurrentTitle().text
    local guessedLanguage = guessLanguage()
    if guessedLanguage then
    local wikiID = guessedLanguage .. "wiki"
    end
    
    if wikiID then
    local entityIdbyCode = mw.wikibase.getEntityIdForTitle( title, wikiID )
    end
    
    if entityIdbyCode then
        return entityIdbyCode
    else
    	return nil
    end
    local debug = guessedLanguage .. wikiID .. entityIdbyCode
    return  debug
end

return p