Jump to content

Module:Korean transliteration notice

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Nonabelian (talk | contribs) at 19:30, 24 July 2024 (Created page with 'local p = {} local categoryHandler = require('Module:Category handler').main local yesno = require('Module:Yesno') local mArguments = require('Module:Arguments') local n 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 n = mArguments.getArgs(frame...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

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

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
        n = mArguments.getArgs(frame, {parentFirst = true})
        n.variant = n.variant or templatetitle
        if n.doc ~= 'no' then
            return frame:expandTemplate {title = 'Korean transliteration notice/documentation', args = n}
        end
    end
    return p._main(frame, templatetitle)
end

function p._main(frame, templatetitle)
    n = mArguments.getArgs(frame, {parentFirst = true})
    n.variant = n.variant or templatetitle
    n.category = ''
    n.transliteration_examples = n.transliteration_examples or n['transliteration examples']
    n.bid = not not n.id

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

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

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

    if bRR then
        n.transliteration_examples = "''Gim'', ''Seoul'', ''Han River''; note that '''-g''' is used instead of -k"
        p.cat('Wikipedia articles that use Revised Romanization')
        if n.bid then n.id = n.id .. n.RR end
        if bMR then
            n.extravariant = ' with [[Revised Romanization|RR]] and [[McCune-Reischauer|MR]] transliteration'
            n.transliteration_examples = n.transliteration_examples .. "; ''Kim'', ''Sŏul'', ''Han-gang''"
            p.MR()
            return
        end
        n.extravariant = n.extravariant .. ' with [[Revised Romanization]]'
        return
    elseif bMR then
        n.extravariant = ' with [[McCune-Reischauer]] transliteration'
        n.transliteration_examples = n.transliteration_examples and n.transliteration_examples .. "; ''Kim'', ''Sŏul'', ''Han-gang''" or "''Kim'', ''Sŏul'', ''Han-gang''"
        p.MR()
        return
    elseif bYale then
        n.extravariant = ' with [[Yale Romanization]]'
        n.transliteration_examples = n.transliteration_examples and n.transliteration_examples .. "; ''Kim'', ''Swuwl'', ''Hankang''" or "''Kim'', ''Swuwl'', ''Hankang''"
        p.Yale()
        return
    end

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

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

function p.Yale()
    n.extraguide = ' and [[Wikipedia:Naming conventions (Korean)|Korean naming conventions]]'
    p.cat('Wikipedia articles that use Yale Romanization')
    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.transliteration_examples = n.transliteration_examples and string.format(' (%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 is '''written in [[%s]]%s'''%s%s and some terms that are used in it%s may be different or absent from %sother [[List of dialects of Korean|varieties of Korean]]. According to the [[Wikipedia:Manual of Style#National varieties of Korean|relevant style guide]]%s, this should not be changed without [[Wikipedia:Consensus#Levels of consensus|broad consensus]].]=],
        n.subjectspace, n.variant, n.extravariant, n.transliteration, n.transliteration_examples, n.terms, n.compare, n.extraguide)
end

function p.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
        if n.flag == nil or yesno(n.flag) then
            n.image = string.format('[[File:%s|%s]]', n.image, size)
        else
            if yesno(n.color) then
                n.image = string.format('[[File:Globe spelling color.png|%s]]', size)
            else
                n.image = string.format('[[File:Globe spelling colour.svg|%s]]', size)
            end
        end
    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
            p.cat(string.format('Pages with %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

return p