打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:Documentation:修订间差异

来自INFWiki
9Yan留言 | 贡献
无编辑摘要
标签已被回退
9Yan留言 | 贡献
无编辑摘要
 
(未显示同一用户的23个中间版本)
第7行: 第7行:
local lang = mw.getContentLanguage()
local lang = mw.getContentLanguage()
local p = {}
local p = {}
-- 如何打印lang
-- 你可以通过调用 lang 对象的方法来获取其信息
mw.log( "当前语言代码: " .. lang:getCode() )
-- 如果你想查看所有后备语言代码
local fallback_langs = lang:getFallbackLanguages()
mw.log( "所有后备语言代码: " .. table.concat(fallback_langs, ", ") )
-- 你还可以获取语言名称(通常是英文)
mw.log( "当前语言名称 (英文): " .. lang:getLanguageName() )
-- 获取本地语言名称(例如,如果是中文,可能显示“中文”)
mw.log( "当前语言名称 (本地): " .. lang:getLanguageName(lang:getCode()) )




第53行: 第39行:
     local page = args[1] or string.gsub( title.fullText, '/[Dd]o[ck]u?$', '' )
     local page = args[1] or string.gsub( title.fullText, '/[Dd]o[ck]u?$', '' )
     local ret, cats, ret1, ret2, ret3
     local ret, cats, ret1, ret2, ret3
     local pageType = title.namespace == 828 and 'module' or 'template'
     local pageType = title.namespace == 828 and 'Module' or 'Template'


     -- subpage header
     -- subpage header
     if title.subpageText == 'doc' then
     if title.subpageText == 'doc' then
ret = mbox(
ret = mbox(
translate( 'message_subpage_title', page ),
'这是模板的文档子页面',
translate( 'message_subpage_desc', page, translate( pageType ) ),
'它包含使用信息以及其他不属于模板页面的内容。',
{ icon = 'WikimediaUI-Notice.svg' }
{ icon = 'WikimediaUI-Notice.svg' }
     )
     )
 
         return tostring( ret )
        if title.namespace == 10 then -- Template namespace
            cats = '[[Category:' .. string.format( t( 'category_documentation' ), t( 'category_' .. pageType ) ) .. '|' .. title.baseText .. ']]'
            ret2 = dependencyList._main()
        elseif title.namespace == 828 then -- Module namespace
            cats = '[[Category:' .. string.format( t( 'category_documentation' ), t( 'category_' .. pageType ) ) .. '|' .. title.baseText .. ']]'
            ret2 = dependencyList._main()
            ret2 = ret2 .. require('Module:Module toc').main()
        else
            cats = ''
            ret2 = ''
        end
 
         return tostring( ret ) .. ret2 .. cats
     end
     end


第87行: 第60行:
             :tag( 'span' )
             :tag( 'span' )
                 :addClass( 'documentation-title' )
                 :addClass( 'documentation-title' )
                 :wikitext( lang:ucfirst( translate('message_documentation_title', pageType ) ) )
                 :wikitext( '模板文档' )
                 :done()
                 :done()
             :tag( 'span' )
             :tag( 'span' )
                 :addClass( 'documentation-links plainlinks' )
                 :addClass( 'documentation-links plainlinks' )
                 :wikitext(
                 :wikitext(
                     '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='view'} ) ) .. ' view]]' ..
                     '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='view'} ) ) .. ' 查看]]' ..
                     '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='edit'} ) ) .. ' edit]]' ..
                     '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='edit'} ) ) .. ' 编辑]]' ..
                     '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='history'} ) ) .. ' history]]' ..
                     '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='history'} ) ) .. ' 历史]]' ..
                     '[<span class="jsPurgeLink">[' .. tostring( mw.uri.fullUrl( title.fullText, { action = 'purge' } ) ) .. ' purge]</span>]'
                     '[<span class="jsPurgeLink">[' .. tostring( mw.uri.fullUrl( title.fullText, { action = 'purge' } ) ) .. ' 刷新]</span>]'
                 )
                 )
                 :done()
                 :done()
第103行: 第76行:
             :tag( 'span' )
             :tag( 'span' )
                 :addClass( 'documentation-documentation' )
                 :addClass( 'documentation-documentation' )
                 :wikitext( translate( 'message_transclude_desc', page ) )
                 :wikitext( '以下是模板的文档,点击右侧按钮去编辑文档' )
                 :done()
                 :done()
             :wikitext( frame:extensionTag{ name = 'templatestyles', args = { src = 'Module:Documentation/styles.css'} } )
             :wikitext( frame:extensionTag{ name = 'templatestyles', args = { src = 'Module:Documentation/styles.css'} } )
第109行: 第82行:


     ret3 = {}
     ret3 = {}
    if args.scwShared then
    --- Message box
    table.insert( ret3,
    mbox(
    translate(
'message_shared_across',
title.fullText,
mw.uri.encode( title.text, 'PATH' )
),
translate(
'message_shared_across_subtext',
pageType
),
{ icon = 'WikimediaUI-ArticleDisambiguation-ltr.svg' }
)
  )
  --- Set category
  table.insert( ret3, '[[Category:' .. string.format( t( 'category_shared_by_the_star_citizen_wikis' ), lang:ucfirst( pageType ) ) .. ']]' )
--- Interlanguage link
--- TODO: Make this into a for loop when there are more wikis
for _, code in pairs{ 'de', 'en' } do
if lang:getCode() ~= code then
    table.insert( ret3, string.format( '[[%s:%s]]', code, title.fullText ) )
end
end
    end
    if args.fromWikipedia then
    table.insert( ret3,
    mbox(
    translate(
'message_from_wikipedia',
title.fullText,
mw.uri.encode( page, 'WIKI' ),
page
),
translate(
'message_from_wikipedia_subtext',
pageType
),
{ icon = 'WikimediaUI-Logo-Wikipedia.svg' }
)
  )
  --- Set category
  table.insert( ret3, '[[Category:' .. string.format( t( 'category_imported_from_wikipedia' ), lang:ucfirst( pageType ) ) .. ']]' )
    end
    if title.namespace == 828 then
    -- Has config
    if mw.title.new( title.fullText .. '/config.json', 'Module' ).exists then
table.insert( ret3,
mbox(
    translate(
    'message_module_configuration',
    title.fullText,
    title.fullText
    ),
    translate( 'message_module_configuration_subtext' ),
    { icon = 'WikimediaUI-Settings.svg' }
    )
)
    end
    -- Has localization
    if mw.title.new( title.fullText .. '/i18n.json', 'Module' ).exists then
table.insert( ret3,
mbox(
    translate(
    'message_module_i18n',
    title.fullText,
    title.fullText
    ),
    translate( 'message_module_i18n_subtext' ),
    { icon = 'WikimediaUI-Language.svg' }
    )
)
    end
    -- Testcase page
    if title.subpageText == 'testcases' then
    table.insert( ret3,
    hatnote(
    translate( 'message_module_tests', title.baseText ),
    { icon = 'WikimediaUI-LabFlask.svg' }
    )
    )
end
table.insert( ret3, string.format( '[[Category:%s]]', t( 'category_module' ) ) )
    end
    --- Dependency list
    table.insert( ret3, dependencyList._main( nil, args.category, args.isUsed ) )
    -- Has templatestyles
if mw.title.new( title.fullText .. '/styles.css' ).exists then
table.insert( ret3,
hatnote(
    translate( 'message_styles', title.fullText, title.fullText ),
    { icon = 'WikimediaUI-Palette.svg' }
    )
)
end
    --- Module stats bar
    if title.namespace == 828 then
table.insert( ret3, '<div class="documentation-modulestats">' )
-- Function list
table.insert( ret3, require( 'Module:Module toc' ).main() )
-- Unit tests
local testcaseTitle = title.baseText .. '/testcases'
if mw.title.new( testcaseTitle, 'Module' ).exists then
-- There is probably a better way :P
table.insert( ret3, frame:preprocess( '{{#invoke:' .. testcaseTitle .. '|run}}' ) )
    end
    table.insert( ret3, '</div>' )
    end


     return ret1 .. tostring( ret2 ) .. '<div class="documentation-content">' .. table.concat( ret3 )
     return ret1 .. tostring( ret2 ) .. '<div class="documentation-content">' .. table.concat( ret3 )

2025年8月3日 (日) 20:00的最新版本

模板文档[查看][编辑][历史][刷新]
以下是模板的文档,点击右侧按钮去编辑文档

Module:Documentation 为模板和模块实现 Template:Documentation


-- <nowiki>
local dependencyList = require( 'Module:DependencyList' )
local hatnote = require( 'Module:Hatnote' )._hatnote
local mbox = require( 'Module:Mbox' )._mbox
local i18n = require( 'Module:i18n' ):new()
local TNT = require( 'Module:Translate' ):new()
local lang = mw.getContentLanguage()
local p = {}


--- Wrapper function for Module:i18n.translate
---
--- @param key string The translation key
--- @return string If the key was not found, the key is returned
local function t( key )
	return i18n:translate( key )
end


--- FIXME: This should go to somewhere else, like Module:Common
--- Calls TNT with the given key
---
--- @param key string The translation key
--- @return string If the key was not found in the .tab page, the key is returned
local function translate( key, ... )
	local success, translation = pcall( TNT.format, 'Module:Documentation/i18n.json', key or '', ... )

	if not success or translation == nil then
		return key
	end

	return translation
end


function p.doc( frame )
    local title = mw.title.getCurrentTitle()
    local args = frame:getParent().args
    local page = args[1] or string.gsub( title.fullText, '/[Dd]o[ck]u?$', '' )
    local ret, cats, ret1, ret2, ret3
    local pageType = title.namespace == 828 and 'Module' or 'Template'

    -- subpage header
    if title.subpageText == 'doc' then
		ret = mbox(
			'这是模板的文档子页面',
			'它包含使用信息以及其他不属于模板页面的内容。',
			{ icon = 'WikimediaUI-Notice.svg' }
    	)
        return tostring( ret )
    end

    -- template header
    -- don't use mw.html as we aren't closing the main div tag
    ret1 = '<div class="documentation">'

    ret2 = mw.html.create( nil )
        :tag( 'div' )
            :addClass( 'documentation-header' )
            :tag( 'span' )
                :addClass( 'documentation-title' )
                :wikitext( '模板文档' )
                :done()
            :tag( 'span' )
                :addClass( 'documentation-links plainlinks' )
                :wikitext(
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='view'} ) ) .. ' 查看]]' ..
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='edit'} ) ) .. ' 编辑]]' ..
                    '[[' .. tostring( mw.uri.fullUrl( page .. '/doc', {action='history'} ) ) .. ' 历史]]' ..
                    '[<span class="jsPurgeLink">[' .. tostring( mw.uri.fullUrl( title.fullText, { action = 'purge' } ) ) .. ' 刷新]</span>]'
                )
                :done()
            :done()
        :tag( 'div' )
            :addClass( 'documentation-subheader' )
            :tag( 'span' )
                :addClass( 'documentation-documentation' )
                :wikitext( '以下是模板的文档,点击右侧按钮去编辑文档' )
                :done()
            :wikitext( frame:extensionTag{ name = 'templatestyles', args = { src = 'Module:Documentation/styles.css'} } )
            :done()

    ret3 = {}

    return ret1 .. tostring( ret2 ) .. '<div class="documentation-content">' .. table.concat( ret3 )
end

return p

-- </nowiki>