Module:TranslationCheck

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 08:39, 28 February 2024 by Vish (talk | contribs) (Created page with "local p = {} function p.checkTranslation(frame) local title = mw.text.trim(frame.args[1] or '') local lang = mw.text.trim(frame.args[2] or '') 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 translation exists for the given title in the specified language if jsonData and jsonData[title] and json...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 '')
    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 translation exists for the given title in the specified language
    if jsonData and jsonData[title] and jsonData[title][lang] then
        -- If the translation exists, return a link to the translated page
        return string.format('[[%s/%s|%s]]', title, lang, displayText)
    else
        -- If the translation does not exist, return a link to the base page
        return string.format('[[%s|%s]]', title, displayText)
    end
end

return p