Jump to content

Module:Korean transliteration notice/sandbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Created page with 'local p = {} local categoryHandler = require('Module:Category handler').main local yesno = require('Module:Yesno') local mArguments = require('Module:Arguments') local n -- Main function function p.main(frame) local fulltitle = frame:getParent():getTitle() local templatetitle = string.sub(fulltitle, 10) local title = mw.title.getCurrentTitle() if mw.title.equals(title, mw.title.makeTitle('Template', title.rootText)) then -- if it is on the...'
 
No edit summary
Line 1: Line 1:
require('strict')

local p = {}
local p = {}
local categoryHandler = require('Module:Category handler').main
local categoryHandler = require('Module:Category handler').main
Line 5: Line 7:
local n
local n


-- Main function
-- Helper functions
function p.main(frame)
local function cat(category)
category = string.format('[[Category:%s]]', category)
local fulltitle = frame:getParent():getTitle()
n.category = n.category .. (categoryHandler{category, nocat = n.nocat, page = n.page, talk = nil, template = category} or '')
local templatetitle = string.sub(fulltitle, 10)
local title = mw.title.getCurrentTitle()
if mw.title.equals(title, mw.title.makeTitle('Template', title.rootText)) then -- if it is on the main template page, load doc
n = mArguments.getArgs(frame, {parentFirst = true})
n.variant = n.variant or templatetitle -- automatically use title generated from template name
if n.doc ~= 'no' then
return frame:expandTemplate {title = 'Korean transliteration notice/documentation', args = n}
end
end
return p._main(frame, templatetitle)
end
end


function p._main(frame, templatetitle)
local function RR()
n.variant = 'Revised Romanization of Korean'
n = mArguments.getArgs(frame, {parentFirst = true})
n.transliteration_examples = "''Joseon'', ''Tteokbokki'', ''Pansori''"
n.variant = n.variant or templatetitle -- automatically use title generated from template name
cat('Wikipedia articles that use the Revised Romanization of Korean')
n.category = ''
if n.bid then n.id = n.id .. 'rr' end
n.transliteration_examples = n.transliteration_examples or n['transliteration examples']
end
n.bid = not not n.id


local function MR()
if not n.text then
n.variant = 'McCune-Reischauer romanization of Korean'
p.modify_text()
n.extraguide = ' and [[Wikipedia:Naming conventions (Korean)|Korean naming conventions]]'
p.base_text(frame)
cat('Wikipedia articles that use the McCune-Reischauer romanization of Korean')
end
n.flag = 'no'
p.cat('Wikipedia articles that use the ' .. n.variant)
return p.style(frame) .. (n.category or '')
if n.bid then n.id = n.id .. 'mr' end
end
end


function p.cat(category)
local function Yale()
n.variant = 'Yale romanization of Korean'
category = string.format('[[Category:%s]]', category)
n.extraguide = ' and [[Wikipedia:Naming conventions (Korean)|Korean naming conventions]]'
n.category = n.category .. (categoryHandler{category, nocat = n.nocat, page = n.page, talk = nil, template = category} or '')
cat('Wikipedia articles that use the Yale romanization of Korean')
n.flag = 'no'
if n.bid then n.id = n.id .. 'yale' end
end
end


function p.modify_text()
local function modify_text()
n.transliteration = ''
n.transliteration = ''
n.extravariant = ''
n.extravariant = ''
n.extraguide = ''
n.extraguide = ''
bRR = yesno(n.RR)
local bRR = yesno(n.RR)
bMR = yesno(n.MR)
local bMR = yesno(n.MR)
bYale = yesno(n.Yale)
local bYale = yesno(n.Yale)


if bRR then
if bRR then
p.RR()
RR()
return
return
elseif bMR then
elseif bMR then
p.MR()
MR()
return
return
elseif bYale then
elseif bYale then
p.Yale()
Yale()
return
return
end
end
Line 62: Line 58:
end
end


function p.RR()
local function base_text(frame)
n.variant = 'Revised Romanization of Korean'
n.transliteration_examples = "''Joseon'', ''Tteokbokki'', ''Pansori''"
p.cat('Wikipedia articles that use the Revised Romanization of Korean')
if n.bid then n.id = n.id .. 'rr' end
end

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

function p.Yale()
n.variant = 'Yale romanization of Korean'
n.extraguide = ' and [[Wikipedia:Naming conventions (Korean)|Korean naming conventions]]'
p.cat('Wikipedia articles that use the Yale romanization of Korean')
n.flag = 'no'
if n.bid then n.id = n.id .. 'yale' end
end

function p.base_text(frame)
n.subjectspace = require('Module:Pagetype').main()
n.subjectspace = require('Module:Pagetype').main()
n.transliteration_examples = n.transliteration_examples and string.format(' (e.g., %s)', n.transliteration_examples) or ''
n.transliteration_examples = n.transliteration_examples and string.format(' (e.g., %s)', n.transliteration_examples) or ''
Line 95: Line 68:
end
end


function p.style(frame)
local function style(frame)
local size
local size
if yesno(n.small) then size = '30px'
if yesno(n.small) then size = '30px'
Line 108: Line 81:
n.expiry = n.expiry or 'indefinite'
n.expiry = n.expiry or 'indefinite'
if yesno(n.editnotice_cat) then
if yesno(n.editnotice_cat) then
p.cat(string.format('Pages with the %s editnotice', n.variant))
cat(string.format('Pages with the %s editnotice', n.variant))
end
end
return frame:expandTemplate{title = 'editnotice', args = n}
return frame:expandTemplate{title = 'editnotice', args = n}
Line 119: Line 92:
end
end


function p.getBasePageName()
local function getBasePageName()
local title = mw.title.getCurrentTitle()
local title = mw.title.getCurrentTitle()
local basePageName = title.text
local basePageName = title.text
Line 136: Line 109:


return basePageName
return basePageName
end
p.getBasePageName = getBasePageName

local function _main(frame, templatetitle)
n = mArguments.getArgs(frame, {parentFirst = true})
n.variant = n.variant or templatetitle -- automatically use title generated from template name
n.category = ''
n.transliteration_examples = n.transliteration_examples or n['transliteration examples']
n.bid = not not n.id

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

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



Revision as of 19:45, 25 July 2024

require('strict')

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

-- Helper functions
local function cat(category)
    category = string.format('[[Category:%s]]', category)
    n.category = n.category .. (categoryHandler{category, nocat = n.nocat, page = n.page, talk = nil, template = category} or '')
end

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

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

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

local function modify_text()
    n.transliteration = ''
    n.extravariant = ''
    n.extraguide = ''
    local bRR = yesno(n.RR)
    local bMR = yesno(n.MR)
    local bYale = yesno(n.Yale)

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

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

local function base_text(frame)
    n.subjectspace = require('Module:Pagetype').main()
    n.transliteration_examples = n.transliteration_examples and string.format(' (e.g., %s)', n.transliteration_examples) or ''
    n.terms = n[1] or n.terms
    n.terms = n.terms and string.format(' (including %s)', n.terms) or ''
    n.compare = n.compare and (n.compare .. ' ') 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 %sother [[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

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

local function getBasePageName()
    local title = mw.title.getCurrentTitle()
    local basePageName = title.text

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

    return basePageName
end
p.getBasePageName = getBasePageName

local function _main(frame, templatetitle)
    n = mArguments.getArgs(frame, {parentFirst = true})
    n.variant = n.variant or templatetitle -- automatically use title generated from template name
    n.category = ''
    n.transliteration_examples = n.transliteration_examples or n['transliteration examples']
    n.bid = not not n.id

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

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

return p