Module:LocalizedLink
Jump to navigation
Jump to search
Documentation for this module may be created at Module:LocalizedLink/doc
local common = require('Module:Common')
local p = {}
function p.main(frame)
local args = common.getArgs(frame)
if #args <= 0 then
return ""
end
local language = common.getContentLanguage(frame)
local link = common.untranslatedTitle(args[1], language)
local display = args[1] -- Default the display to the page name
local anchor = ""
if args.anchor then
anchor = "#" .. args.anchor
end
if args[2] then
-- If a display is present use it as the link display
display = args[2]
else
-- Test if the user has input an escaped pipe (eg; "page{{!}}display")
local m1, m2 = args[1]:match('^(.*)%|(.*)$')
if m1 and m2 then
link = m1
display = m2
else
display = common.localizedTitle(link, language)
end
end
local comment = language
-- Pathify the language
if language == "" then
language = ""
else
language = "/" .. language
end
return '[[:' .. link .. language .. anchor .. '|' .. display .. ']]'
end
return p