模块:NoteTA
来自能源智库
SolarLib(讨论 | 贡献)2016年8月5日 (五) 17:13的版本 (创建页面,内容为“local z = {} local WikitextLC = require( 'Module:WikitextLC' ) function Tcode( args ) if args.T == nil or args.T == '' then return '' end local div = mw.html.c...”)
Lua错误:无法创建进程:proc_open不可用。请检查PHP的指令配置“disable_functions”。 模板:字詞轉換索引
模板说明
本模板用来在一個頁面裡,轉換不同地區的翻譯用語或指定特定的標題。加入此模板的页面顶部会出现noteTA(本页使用了标题或全文手工转换)标志。
使用說明
用法為:
{{noteTA |T = -{zh-hans:标题转换; zh-hant:標題轉換;}- |G1 = 公共转换组1 |G2 = 公共转换组2 …… |Gm = 公共转换组m |F1 = 固定转换规则1 |F2 = 固定转换规则2 …… |Fm = 固定转换规则m |1 = -{zh-cn:转换用词; zh-tw:轉換用詞;}-1 |2 = -{zh-cn:转换用词; zh-tw:轉換用詞;}-2 …… |n = -{zh-cn:转换用词; zh-tw:轉換用詞;}-n }}
其中「T」是標題转换。
「m」是序號數,最大為10,「n」是序號數,最大為30。
G1至G10参数用来导入一些已定义好的公共转换组,比如物理学。直接引用公共转换组有很多好处,方便在一个领域和主题的条目中共同使用,方便维护,没有个数限制,可以实现单向转换。
可展開下面的列表查詢可用的公共轉換組,或查閱Category:公共轉換組模板分類。關於公共轉換組的詳細說明和創建過程可查閱Wikipedia:字詞轉換處理/公共組轉換。
示例
- 例一(使用全文转换):
{{noteTA |1 = zh:量子計算機; zh-cn:量子计算机; zh-tw:量子計算機; |2 = zh:信息; zh-cn:信息; zh-tw:資訊; }}
- 例二(使用标题转换和两个全文转换):
{{noteTA |T = zh-cn:迈克尔·杰克逊; zh-hk:米高積遜; zh-tw:麥可·傑克森; |1 = zh-cn:迈克尔; zh-hk:米高; zh-tw:麥可; |2 = zh-cn:杰克逊; zh-hk:積遜; zh-tw:傑克森; }}
- 例三(引入變形金剛組转换,同时增加一个单独的全文转换):
{{noteTA |G1 = 變形金剛 |1 = zh-cn:迈克尔·贝; zh-tw:麥可·貝; }}
- 例四(單向轉換):
{{noteTA |1 = 例四地區=>zh-cn:例四大陆; 例四地區=>zh-hk:例四香港; 例四地區=>zh-tw:例四台灣; }}
- 在例四,由於沒有加入zh-sg的單向轉換規則,在「馬新簡體」下「字詞轉換」方框可能顯示紅字「在手动语言转换规则中检测到错误」,如有需要,可再加上適用的「...=>zh-sg:...;」轉換。
模板数据
进阶使用说明
本模板还可以添加一些命名参数,以用于更广泛的目的。以下为参数的解释:
- dt:标题转换的说明,填写该参数时,标题转换的说明以该参数为准。
- d1,d2……d30: 用于对第n个全文转换进行说明,填写该参数时,该转换的说明以该参数为准。
其他注意事項
請在填上各地區的標題轉換後,順道為各地區的標題建立重定向頁,因為填寫NoteTA並不會自動建立地區標題重定向的。
若某條目被掛上{{TARequired}}者,表示需要加入人工地區詞轉換模板{{NoteTA}}。需要NoteTA模板的頁面
如果要在模板内使用本模板,请将本模板置于<noinclude></noinclude>
内,避免与包含其的页面的noteTA模板产生冲突(特点为条目标题栏仍有一个noteTA的标志)。
脚本错误:Lua错误:无法创建进程:proc_open不可用。请检查PHP的指令配置“disable_functions”。
local z = {}
local WikitextLC = require( 'Module:WikitextLC' )
function Tcode( args )
if args.T == nil or args.T == '' then
return ''
end
local div = mw.html.create( 'div' )
:attr( 'class', 'noteTA-title' )
:attr( 'data-noteta-code', args.T )
:wikitext( WikitextLC.title( args.T ) )
if args.dt ~= nil and args.dt ~= '' then
div:attr( 'data-noteta-desc', args.dt )
end
return tostring( div )
end
function group( name, frame )
if name == nil or name == '' then
return ''
end
local moduleTitle = mw.title.makeTitle( 'Module', 'CGroup/' .. name )
if moduleTitle and moduleTitle.exists then
local data = require( 'Module:CGroup/' .. name )
local pieces = {}
if data.content then
for i, v in ipairs( data.content ) do
if v.type == 'item' and v.rule then
table.insert( pieces, '-{H|' .. v.rule .. '}-' )
end
end
return tostring( mw.html.create( 'div' )
:attr( 'data-noteta-group-source', 'module' )
:attr( 'data-noteta-group', data.name or name )
:wikitext( table.concat( pieces ) ) )
end
end
local templateTitle = mw.title.makeTitle( 'Template', 'CGroup/' .. name )
if templateTitle and templateTitle.exists then
return frame:expandTemplate{ title = templateTitle }
end
return tostring( mw.html.create( 'div' )
-- :attr( 'id', 'noteTA-group-' .. mw.uri.anchorEncode( name ) )
:attr( 'data-noteta-group-source', 'none' )
:attr( 'data-noteta-group', name ) )
end
function Gcode( args, frame )
local code = {}
for i = 1, 30 do
table.insert( code, group( args['G' .. i], frame ) )
end
code = table.concat( code )
if code ~= '' then
code = tostring( mw.html.create( 'div' )
:attr( 'class', 'noteTA-group' )
:wikitext( code ) )
if args.G31 ~= nil then
code = code .. '[[Category:NoteTA模板参数使用数量超过限制的页面|G]]'
end
end
return code
end
function local_( i, code, desc )
if code == nil or code == '' then
return ''
end
local div = mw.html.create( 'div' )
-- :attr( 'id', 'noteTA-local-' .. i )
:attr( 'data-noteta-code', code )
:wikitext( WikitextLC.hidden( code ) )
if desc ~= nil and desc ~= '' then
div:attr( 'data-noteta-desc', desc )
end
return tostring( div )
end
function Lcode( args )
local code = {}
for i = 1, 30 do
table.insert( code, local_( i, args[i], args['d' .. i] ) )
end
code = table.concat( code )
if code ~= '' then
code = tostring( mw.html.create( 'div' )
:attr( 'class', 'noteTA-local' )
:wikitext( code ) )
if args[31] ~= nil then
code = code .. '[[Category:NoteTA模板参数使用数量超过限制的页面|L]]'
end
end
return code
end
function z.main( frame )
local args
if frame == mw.getCurrentFrame() then
-- Being called from {{noteTA}}
args = frame:getParent().args
else
-- Being called from another module
args = frame
frame = mw.getCurrentFrame()
end
local Tc = Tcode( args )
local Gc = Gcode( args, frame )
local Lc = Lcode( args )
local code = Tc .. Gc .. Lc
if code ~= '' then
local hash = require( 'Module:Crc32lua' ).crc32( mw.dumpObject( args ) )
code = frame:extensionTag{
name = 'indicator',
content = '[[File:Zh conversion icon m.svg|35px|本页使用了标题或全文手工转换|link=]]',
args = { name = string.format( 'noteTA-%x', hash ) },
} .. tostring( mw.html.create( 'div' )
:attr( 'id', string.format( 'noteTA-%x', hash ) )
:attr( 'class', 'noteTA' )
:wikitext( code ) )
if mw.title.getCurrentTitle():inNamespace( 'Template' ) then
code = code .. '[[Category:放置于模板的noteTA]]'
end
end
return code
end
return z