mNo edit summary |
m (Reverted edits by Xbony2 (talk) to last revision by TheSatanicSanta) Tag: Rollback |
||
Line 1: | Line 1: | ||
− | local langNames = |
+ | local langNames = mw.loadData( [[Module:Language/Names]] ) |
− | local |
+ | local code = function( title ) |
⚫ | |||
− | |||
− | local function code( title ) |
||
⚫ | |||
− | if not titleObj.isSubpage then |
||
− | return nil |
||
⚫ | |||
− | local subPage = titleObj.subpageText:lower() |
||
if langNames[subPage] then |
if langNames[subPage] then |
||
return subPage |
return subPage |
||
end |
end |
||
end |
end |
||
− | local |
+ | local pageSuffix = function() |
local langCode = code() |
local langCode = code() |
||
if langCode then |
if langCode then |
||
Line 22: | Line 16: | ||
local p = {} |
local p = {} |
||
− | -- See {{L}} |
||
p.link = function( f ) |
p.link = function( f ) |
||
− | local args = |
+ | local args = f or {} |
+ | if f == mw.getCurrentFrame() then |
||
+ | args = f:getParent().args |
||
⚫ | |||
-- Get language suffix for links |
-- Get language suffix for links |
||
Line 32: | Line 28: | ||
local page = args[1] .. pageSuffix() |
local page = args[1] .. pageSuffix() |
||
− | |||
-- Get page name with suffix |
-- Get page name with suffix |
||
if args.dest then |
if args.dest then |
||
return page |
return page |
||
end |
end |
||
− | |||
-- Get page link with suffix and specified text |
-- Get page link with suffix and specified text |
||
return '[[' .. page .. '|' .. ( args.o or args[2] or args[1] ) .. ']]' |
return '[[' .. page .. '|' .. ( args.o or args[2] or args[1] ) .. ']]' |
||
end |
end |
||
− | -- See {{Language}} |
||
p.name = function( f ) |
p.name = function( f ) |
||
− | local args = |
+ | local args = f |
+ | if f == mw.getCurrentFrame() then |
||
+ | args = f:getParent().args |
||
⚫ | |||
− | local langCode = code(args[1] and mw.title.new(args[1])) or 'en' |
+ | local langCode = code( args[1] and mw.title.new( args[1] ) ) or 'en' |
-- Get language code for specified title or current page |
-- Get language code for specified title or current page |
||
Line 54: | Line 50: | ||
local langName = langNames[langCode] |
local langName = langNames[langCode] |
||
⚫ | |||
− | |||
⚫ | |||
− | -- Get language name in English if the 2nd arg or 'en' arg is set |
||
− | if (args[2] and args[2] ~= '') or (args.en and args.en ~= '') then |
||
return langName[1] |
return langName[1] |
||
end |
end |
||
+ | -- Get native name |
||
− | |||
⚫ | |||
return langName[2] |
return langName[2] |
||
end |
end |
||
+ | -- This is not a communist function |
||
− | -- See {{ML}} |
||
− | p.modlink = function( |
+ | p.modlink = function(f) |
− | local args = |
+ | local args = f or {} |
+ | if f == mw.getCurrentFrame() then |
||
+ | args = f:getParent().args |
||
⚫ | |||
− | local |
+ | local name = require([[Module:Mods]]).getName(args[2]) |
− | if not |
+ | if not name then |
return 'No mod found' |
return 'No mod found' |
||
end |
end |
||
+ | args[2] = args[1] |
||
− | local disambiguated = string.format("%s (%s)", args[1], modname) |
||
+ | args[1] = args[1] .. ' (' .. name .. ')' |
||
− | |||
− | return p.link{disambiguated, args.title or args[1]} |
||
⚫ | |||
− | |||
− | p.code = function( f ) |
||
− | local args = processArgs.norm( f ) |
||
− | |||
− | -- 'de' and 'Main Page/de' will be correctly processed regardless of the arg name |
||
− | -- These aliases are mainly to keep a standard |
||
− | local selected = args.code or args.title |
||
− | |||
− | local code = code( selected and mw.title.new(selected) or mw.title.getCurrentTitle() ) |
||
− | |||
⚫ | |||
− | return args.default or '' |
||
⚫ | |||
− | return |
+ | return p.link(args) |
end |
end |
||
Revision as of 21:12, 28 November 2020
Documentation for this module may be created at Module:Language/doc
local langNames = mw.loadData( [[Module:Language/Names]] )
local code = function( title )
local subPage = ( title or mw.title.getCurrentTitle() ).subpageText:lower()
if langNames[subPage] then
return subPage
end
end
local pageSuffix = function()
local langCode = code()
if langCode then
return '/' .. langCode
end
return ''
end
local p = {}
p.link = function( f )
local args = f or {}
if f == mw.getCurrentFrame() then
args = f:getParent().args
end
-- Get language suffix for links
if not args[1] or args[1]:lower() == 't' then
return pageSuffix()
end
local page = args[1] .. pageSuffix()
-- Get page name with suffix
if args.dest then
return page
end
-- Get page link with suffix and specified text
return '[[' .. page .. '|' .. ( args.o or args[2] or args[1] ) .. ']]'
end
p.name = function( f )
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
end
local langCode = code( args[1] and mw.title.new( args[1] ) ) or 'en'
-- Get language code for specified title or current page
if args.code then
return langCode
end
local langName = langNames[langCode]
-- Get language name
if args.en then
return langName[1]
end
-- Get native name
return langName[2]
end
-- This is not a communist function
p.modlink = function(f)
local args = f or {}
if f == mw.getCurrentFrame() then
args = f:getParent().args
end
local name = require([[Module:Mods]]).getName(args[2])
if not name then
return 'No mod found'
end
args[2] = args[1]
args[1] = args[1] .. ' (' .. name .. ')'
return p.link(args)
end
return p