Module:Korean transliteration notice and Module:Korean transliteration notice/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
imported>Nonabelian
Provide explanations
 
imported>Nonabelian
No edit summary
 
Line 1: Line 1:
require('strict') -- Enforce strict variable handling to catch undeclared global variables
require('strict')


-- Import modules
local p = {}
local p = {}  
local categoryHandler = require('Module:Category handler').main
local categoryHandler = require('Module:Category handler').main  
local yesno = require('Module:Yesno')
local yesno = require('Module:Yesno')  
local mArguments = require('Module:Arguments')
local mArguments = require('Module:Arguments')  
local n
local n  


-- define local functions
-- Define functions
 
-- Function to categorize pages
local function cat(category)
local function cat(category)
-- Format the category string
category = string.format('[[Category:%s]]', category)
category = string.format('[[Category:%s]]', category)
-- Concatenate the category to n.category using categoryHandler
n.category = n.category .. category
n.category = n.category..(categoryHandler{
category,
nocat = n.nocat,
page = n.page,
talk = category
} or '')
end
end


-- Function to handle Revised Romanization of Korean
local function RR()
local function RR()
n.variant = 'Revised Romanization of Korean'
    mw.log('Inside RR function')
n.transliteration_examples = "''Joseon'', ''Tteokbokki'', ''Pansori''"
    n.variant = 'Revised Romanization of Korean'
cat('Wikipedia articles that use the Revised Romanization of Korean')
    n.transliteration_examples = "''Joseon'', ''Tteokbokki'', ''Pansori''"
if n.bid then n.id = n.id .. 'rr' end
    cat('Wikipedia articles that use the Revised Romanization of Korean')
    if n.bid then n.id = n.id .. 'rr' end
end
end


-- Function to handle McCune-Reischauer romanization of Korean
local function MR()
local function MR()
n.variant = 'McCune-Reischauer romanization of Korean'
    mw.log('Inside MR function')
n.extraguide = ' and [[Wikipedia:Naming conventions (Korean)|Korean naming conventions]]'
    n.variant = 'McCune-Reischauer romanization of Korean'
cat('Wikipedia articles that use the McCune-Reischauer romanization of Korean')
    n.extraguide = ' and [[Wikipedia:Naming conventions (Korean)|Korean naming conventions]]'
n.flag = 'no'
    cat('Wikipedia articles that use the McCune-Reischauer romanization of Korean')
if n.bid then n.id = n.id .. 'mr' end
    n.flag = 'no'
    if n.bid then n.id = n.id .. 'mr' end
end
end


-- Function to handle Yale romanization of Korean
local function Yale()
local function Yale()
n.variant = 'Yale romanization of Korean'
    mw.log('Inside Yale function')
n.extraguide = ' and [[Wikipedia:Naming conventions (Korean)|Korean naming conventions]]'
    n.variant = 'Yale romanization of Korean'
cat('Wikipedia articles that use the Yale romanization of Korean')
    n.extraguide = ' and [[Wikipedia:Naming conventions (Korean)|Korean naming conventions]]'
n.flag = 'no'
    cat('Wikipedia articles that use the Yale romanization of Korean')
if n.bid then n.id = n.id .. 'yale' end
    n.flag = 'no'
    if n.bid then n.id = n.id .. 'yale' end
end
end


-- Function to modify text based on transliteration system selected
local function modify_text()
local function modify_text()
n.transliteration = ''
    mw.log('Inside modify_text function')
n.extravariant = ''
    n.transliteration = ''
n.extraguide = ''
    n.extravariant = ''
local bRR = yesno(n.RR)
    n.extraguide = ''
local bMR = yesno(n.MR)
    local bRR = yesno(n.RR)
local bYale = yesno(n.Yale)
    local bMR = yesno(n.MR)
    local bYale = yesno(n.Yale)


if bRR then
    if bRR then
RR()
        RR()
return
        return
elseif bMR then
    elseif bMR then
MR()
        MR()
return
        return
elseif bYale then
    elseif bYale then
Yale()
        Yale()
return
        return
end
    end


if n.transliteration_examples then n.transliteration = ', which has its own [[transliteration]] conventions' end
    if n.transliteration_examples then n.transliteration = ', which has its own [[transliteration]] conventions' end
end
end


-- Function to generate the base text for the notice
local function base_text(frame)
local function base_text(frame)
n.subjectspace = require('Module:Pagetype').main()
    mw.log('Inside base_text function')
n.transliteration_examples = n.transliteration_examples and string.format(' (e.g., %s)', n.transliteration_examples) or ''
    n.subjectspace = require('Module:Pagetype').main()
n.terms = n[1] or n.terms
    n.transliteration_examples = n.transliteration_examples and string.format(' (e.g., %s)', n.transliteration_examples) or ''
n.terms = n.terms and string.format(' (including %s)', n.terms) or ''
    n.terms = n[1] or n.terms
n.compare = n.compare and (n.compare .. ' ') or ''
    n.terms = n.terms and string.format(' (including %s)', n.terms) or ''
n.text = string.format([=[This %s '''uses the [[%s]]%s'''%s%s and some terms that are used in it%s may be different or absent from %sor other [[Romanization of Korean|romanizations of Korean]]. According to the [[MOS:KO|relevant Korean style guide]]%s, this should not be changed without [[Wikipedia:Consensus#Levels of consensus|broad consensus]]. Per [[WP:COMMONNAME]], use words commonly established in English over any transliteration if they exist.]=],
    n.compare = n.compare and (n.compare .. ' ') or ''
n.subjectspace, n.variant, n.extravariant, n.transliteration, n.transliteration_examples, n.terms, n.compare, n.extraguide)
    n.text = string.format([=[This %s '''uses the [[%s]]%s'''%s%s and some terms that are used in it%s may be different or absent from %sor other [[Romanization of Korean|romanizations of Korean]]. According to the [[MOS:KO|relevant Korean style guide]]%s, this should not be changed without [[Wikipedia:Consensus#Levels of consensus|broad consensus]]. Per [[WP:COMMONNAME]], use words commonly established in English over any transliteration if they exist.]=],
        n.subjectspace, n.variant, n.extravariant, n.transliteration, n.transliteration_examples, n.terms, n.compare, n.extraguide)
end
end


-- Function to style the notice based on given parameters
local function style(frame)
local function style(frame)
local size
    mw.log('Inside style function')
if yesno(n.small) then size = '30px'
    local size
elseif n.size then size = n.size
    if yesno(n.small) then size = '30px'
else size = '50px'
    elseif n.size then size = n.size
end
    else size = '50px'
if n.image then
    end
n.image = string.format('[[File:%s|%s]]', n.image, size)
    if n.image then
end
        n.image = string.format('[[File:%s|%s]]', n.image, size)
if n.form == 'editnotice' then
    end
if n.bid then n.id = n.id .. 'editnotice' end
    if n.form == 'editnotice' then
n.expiry = n.expiry or 'indefinite'
        if n.bid then n.id = n.id .. 'editnotice' end
if yesno(n.editnotice_cat) then
        n.expiry = n.expiry or 'indefinite'
cat(string.format('Pages with the %s editnotice', n.variant))
        if yesno(n.editnotice_cat) then
end
            cat(string.format('Pages with the %s editnotice', n.variant))
return frame:expandTemplate{title = 'editnotice', args = n}
        end
else
        return frame:expandTemplate{title = 'editnotice', args = n}
local message_box = require('Module:Message box').main
    else
if not n.image then n.image = 'none' end
        local message_box = require('Module:Message box').main
n['type'] = 'style'
        if not n.image then n.image = 'none' end
return message_box('tmbox', n)
        n['type'] = 'style'
end
        return message_box('tmbox', n)
    end
end
end


-- Function to get the base page name for special cases (used for documentation pages)
local function getBasePageName()
local function getBasePageName()
local title = mw.title.getCurrentTitle()
    mw.log('Inside getBasePageName function')
local basePageName = title.text
    local title = mw.title.getCurrentTitle()
    local basePageName = title.text


-- Handle specific cases
    -- Handle specific cases
if basePageName:find("McCune-Reischauer romanization of Korean") then
    if basePageName:find("McCune-Reischauer romanization of Korean") then
basePageName = "McCune-Reischauer"
        basePageName = "McCune-Reischauer"
elseif basePageName:find("Yale romanization of Korean") then
    elseif basePageName:find("Yale romanization of Korean") then
basePageName = "Yale romanization"
        basePageName = "Yale romanization"
elseif basePageName:find("Revised Romanization of Korean") then
    elseif basePageName:find("Revised Romanization of Korean") then
basePageName = "Revised Romanization"
        basePageName = "Revised Romanization"
else
    else
basePageName = basePageName:gsub(" romanization of Korean", "")
        basePageName = basePageName:gsub(" romanization of Korean", "")
basePageName = basePageName:gsub(" of Korean", "")
        basePageName = basePageName:gsub(" of Korean", "")
end
    end


return basePageName
    return basePageName
end
end
p.getBasePageName = getBasePageName
p.getBasePageName = getBasePageName


-- Main function for handling the setup and categorization
local function _main(frame, templatetitle)
local function _main(frame, templatetitle)
n = mArguments.getArgs(frame, {parentFirst = true})
    mw.log('Inside _main function')
n.variant = n.variant or templatetitle -- automatically use title generated from template name
    n = mArguments.getArgs(frame, {parentFirst = true})
n.category = ''
    n.variant = n.variant or templatetitle -- automatically use title generated from template name
n.transliteration_examples = n.transliteration_examples or n['transliteration examples']
    n.category = ''
n.bid = not not n.id
    n.transliteration_examples = n.transliteration_examples or n['transliteration examples']
    n.bid = not not n.id


if not n.text then
    if not n.text then
modify_text()
        modify_text()
base_text(frame)
        base_text(frame)
end
    end
cat('Wikipedia articles that use the ' .. n.variant)
    cat('Wikipedia articles that use the ' .. n.variant)
return style(frame) .. (n.category or '')
    return style(frame) .. (n.category or '')
end
end
p._main = _main
p._main = _main


-- Main entry point for the module
-- Main function
function p.main(frame)
function p.main(frame)
local fulltitle = frame:getParent():getTitle()
    mw.log('Inside main function')
local templatetitle = string.sub(fulltitle, 10)
    local fulltitle = frame:getParent():getTitle()
local title = mw.title.getCurrentTitle()
    local templatetitle = string.sub(fulltitle, 10)
if mw.title.equals(title, mw.title.makeTitle('Template', title.rootText)) then -- if it is on the main template page, load doc
    local title = mw.title.getCurrentTitle()
n = mArguments.getArgs(frame, {parentFirst = true})
    if mw.title.equals(title, mw.title.makeTitle('Template', title.rootText)) then -- if it is on the main template page, load doc
n.variant = n.variant or templatetitle -- automatically use title generated from template name
        n = mArguments.getArgs(frame, {parentFirst = true})
if n.doc ~= 'no' then
        n.variant = n.variant or templatetitle -- automatically use title generated from template name
return frame:expandTemplate {title = 'Korean transliteration notice/documentation', args = n}
        if n.doc ~= 'no' then
end
            return frame:expandTemplate {title = 'Korean transliteration notice/documentation', args = n}
end
        end
return _main(frame, templatetitle)
    end
    return _main(frame, templatetitle)
end
end


return p
return p