LLWiki正在建设中,欢迎加入我们

模块:NoteTA

来自LLWiki
跳转到导航 跳转到搜索
模块文档
这个文档嵌入Module:NoteTA/doc

说明

本模板用来在一个页面里,转换不同地区的翻译用语或指定特定的标题。加入此模板的页面顶部会出现noteTA(本页使用了标题或全文手工转换)标识。

使用方法

用法:

{{NoteTA
|T  = 标题
|G1 = 公共转换组1
|G2 = 公共转换组2
…
|Gn = 公共转换组n
|1  = 转换用词1
|2  = 转换用词2
…
|n = 转换用词n
}}

其中T是标题转换;n是序号数,最大为30。

G1至G30参数用来导入一些已定义好的公共转换组,比如LoveLive!学园偶像祭。直接引用公共转换组有很多好处,方便在一个领域和主题的条目中共同使用,方便维护,没有个数限制,可以实现单向转换。

  1. local z = {}
  2. local function Tcode( args )
  3. if args.T == nil or args.T == '' then
  4. return ''
  5. end
  6. local div = mw.html.create( 'div' )
  7. :attr( 'class', 'noteTA-title' )
  8. :attr( 'data-noteta-code', args.T )
  9. :wikitext( '-{T|' .. args.T .. '}-' )
  10. if args.dt ~= nil and args.dt ~= '' then
  11. div:attr( 'data-noteta-desc', args.dt )
  12. end
  13. return tostring( div )
  14. end
  15. local function group( name )
  16. if name == nil or name == '' then
  17. return ''
  18. end
  19. local moduleTitle = mw.title.makeTitle( 'Module', 'CGroup/' .. name )
  20. if moduleTitle and moduleTitle.exists then
  21. local data = require( 'Module:CGroup/' .. name )
  22. local pieces = {}
  23. if data.content then
  24. for i, v in ipairs( data.content ) do
  25. if v.type == 'item' and v.rule then
  26. table.insert( pieces, '-{H|' .. v.rule .. '}-' )
  27. end
  28. end
  29. return tostring( mw.html.create( 'div' )
  30. :attr( 'data-noteta-group-source', 'module' )
  31. :attr( 'data-noteta-group', data.name or name )
  32. :wikitext( table.concat( pieces ) ) )
  33. end
  34. end
  35. end
  36. local function Gcode( args )
  37. local code = {}
  38. for i = 1, 30 do
  39. table.insert( code, group( args['G' .. i] ) )
  40. end
  41. code = table.concat( code )
  42. if code ~= '' then
  43. code = tostring( mw.html.create( 'div' )
  44. :attr( 'class', 'noteTA-group' )
  45. :wikitext( code ) )
  46. if args.G31 ~= nil then
  47. code = code .. '[[Category:NoteTA模板参数使用数量超过限制的页面|G]]'
  48. end
  49. end
  50. return code
  51. end
  52. local function local_( code, desc )
  53. if code == nil or code == '' then
  54. return ''
  55. end
  56. local div = mw.html.create( 'div' )
  57. -- :attr( 'id', 'noteTA-local-' .. i )
  58. :attr( 'data-noteta-code', code )
  59. :wikitext( '-{H|' .. code .. '}-' )
  60. if desc ~= nil and desc ~= '' then
  61. div:attr( 'data-noteta-desc', desc )
  62. end
  63. return tostring( div )
  64. end
  65. local function Lcode( args )
  66. local code = {}
  67. for i = 1, 30 do
  68. table.insert( code, local_( args[i], args['d' .. i] ) )
  69. end
  70. code = table.concat( code )
  71. if code ~= '' then
  72. code = tostring( mw.html.create( 'div' )
  73. :attr( 'class', 'noteTA-local' )
  74. :wikitext( code ) )
  75. if args[31] ~= nil then
  76. code = code .. '[[Category:NoteTA模板参数使用数量超过限制的页面|L]]'
  77. end
  78. end
  79. return code
  80. end
  81. function z.main( frame )
  82. local args
  83. if frame == mw.getCurrentFrame() then
  84. -- Being called from {{noteTA}}
  85. args = frame:getParent().args
  86. else
  87. -- Being called from another module
  88. args = frame
  89. frame = mw.getCurrentFrame()
  90. end
  91. local Tc = Tcode( args )
  92. local Gc = Gcode( args )
  93. local Lc = Lcode( args )
  94. local code = Tc .. Gc .. Lc
  95. if code ~= '' then
  96. code = frame:extensionTag{
  97. name = 'indicator',
  98. content = '[[File:Zh conversion icon m.png|35px|本页使用了标题或全文手工转换|link=]]',
  99. args = { name = 'noteTA' },
  100. } ..
  101. tostring( mw.html.create( 'div' )
  102. :attr( 'id', 'mw-mobile-noteTA' )
  103. :addClass( 'mobileonly' )
  104. :cssText( 'position:absolute;right:0;top:-6.5em;' )
  105. :wikitext( '[[File:Zh conversion icon m.png|70px|本页使用了标题或全文手工转换|link=]]' ) ) ..
  106. tostring( mw.html.create( 'div' )
  107. :attr( 'id', 'noteTA' )
  108. :addClass( 'noteTA' )
  109. :wikitext( code ) )
  110. --if mw.title.getCurrentTitle():inNamespace( 'Template' ) then
  111. --code = code .. '[[Category:放置于模板的noteTA]]'
  112. --end
  113. end
  114. return code
  115. end
  116. return z