Feed The Beast Wiki

Follow the Feed The Beast Wiki on Discord or Mastodon!

READ MORE

Feed The Beast Wiki
(Pipe trick testing)
 
(Use Module:Pipe Trick)
Line 1: Line 1:
 
local langNames = require( [[Module:Language/Names]] )
 
local langNames = require( [[Module:Language/Names]] )
 
local processArgs = require( [[Module:ProcessArgs]] )
 
local processArgs = require( [[Module:ProcessArgs]] )
  +
local pipeTrick = require( [[Module:Pipe Trick]] )
   
 
local function code( title )
 
local function code( title )
Line 37: Line 38:
 
if args.dest then
 
if args.dest then
 
return page
 
return page
  +
end
  +
  +
local usePipeTrick = args.o == '' or args[2] == ''
  +
if usePipeTrick then
  +
return pipeTrick.link(page)
 
end
 
end
   

Revision as of 01:09, 28 December 2020

Documentation for this module may be created at Module:SizableShrimp/Language/doc

local langNames = require( [[Module:Language/Names]] )
local processArgs = require( [[Module:ProcessArgs]] )
local pipeTrick = require( [[Module:Pipe Trick]] )

local function code( title )
	local titleObj = title or mw.title.getCurrentTitle()
	if not titleObj.isSubpage then
		return nil
	end
	local subPage = titleObj.subpageText:lower()
	if langNames[subPage] then
		return subPage
	end
end
local function pageSuffix()
	local langCode = code()
	if langCode then
		return '/' .. langCode
	end
	return ''
end

local p = {}

-- See {{L}}
p.link = function( f )
	-- Set keepEmptyArgs to true to allow pipe trick
	local args = processArgs.normDefault( f, true )
	
	-- 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
	
	local usePipeTrick = args.o == '' or args[2] == ''
	if usePipeTrick then
		return pipeTrick.link(page)
	end

	-- Get page link with suffix and specified text
	return '[[' .. page .. '|' .. ( args.o or args[2] or args[1] ) .. ']]'
end

-- See {{Language}}
p.name = function( f )
	local args = processArgs.normDefault( f )
	
	local langCode = 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 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]
	end
	
	-- Get language name in that language (autonym)
	return langName[2]
end

-- See {{ML}}
p.modlink = function( f )
	local args = processArgs.normDefault( f )
	
	local modname = require([[Module:Mods]]).getData(args[2]).name
	
	if not modname then
		return 'No mod found'
	end
	
	local disambiguated = string.format("%s (%s)", args[1], modname)
	
	return p.link{disambiguated, args.title or args[1]}
end

p.code = function( f )
	local args = processArgs.normDefault( 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() )
	
	if not code then
		return args.default or ''
	end
	
	return code
end

return p