Module:TranslationCheck

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 08:45, 28 February 2024 by Vish (talk | contribs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:TranslationCheck/doc

local p = {}

function p.checkTranslation(frame)
    local title = mw.text.trim(frame.args[1] or '')
    local lang = mw.text.trim(frame.args[2] or '') -- Language code
    local displayText = frame.args[3] or title

    -- Load the JSON data directly from the "JoJo Wiki:Translated_Pages" page
    local jsonData = mw.loadJsonData('JoJo Wiki:Translated_Pages')

    -- Check if the specified language exists in the JSON data
    if jsonData and jsonData[lang] then
        -- Iterate through the list of page titles for the specified language
        for _, translatedTitle in ipairs(jsonData[lang]) do
            -- Check if the current title matches the requested title
            if translatedTitle == title .. '/' .. lang then
                -- If a match is found, return a link to the translated page
                return string.format('[[%s|%s]]', translatedTitle, displayText)
            end
        end
    end

    -- If no translation is found or the language does not exist, return a link to the base page
    return string.format('[[%s|%s]]', title, displayText)
end

return p