Documentation for this module may be created at Module:TranslationCheck/doc
local p = {}
function p.unEscapeCategory(title)
-- Get category namespace page name from escaped link
if string.sub(title,1,10) == ':Category:' then
return string.sub(title,2)
end
return title
end
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 escapedTitle = p.unEscapeCategory(title) -- Actual page name for categories
local displayText = frame.args[3] or escapedTitle
-- 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 == escapedTitle .. '/' .. lang then
-- If a match is found, return a link to the translated page (do not escape categories)
return string.format('[[%s|%s]]', title .. '/' .. lang, 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