Module:LangSwitch: Difference between revisions

From Test Wiki
Content deleted Content added
per edit request
m 1 revision imported
Tags: Mobile edit Mobile web edit
 
(One intermediate revision by one other user not shown)
Line 13: Line 13:
-- add optional module
-- add optional module
-- used for debugging purposes as it detects cases of unintended global variables
-- used for debugging purposes as it detects cases of unintended global variables
require('strict')
require('Module:No globals')


local p = {}
local p = {}

local function add_labels(args)
-- add invisible but machine readable labels to the files, which can be used to add titles to wikidata items
local createTag = require('Module:TagQS').createTag -- lazy loading of the module: only for the files that need it
local qsTable = {''}

-- add text of invisible tag brodcasted by the template which allows creation of QuickStatements command used to add this info to Wikidata
for lang, text in pairs( args ) do
if type(lang)=='string' and mw.language.isSupportedLanguage(lang) then -- lang has to be a valid language
table.insert( qsTable, createTag('label', 'L'..lang, '"' .. text .. '"') )
end
end
return table.concat( qsTable, '\n')
end


--[[
--[[
Line 108: Line 94:
if not lang or not mw.language.isKnownLanguageTag(lang) then
if not lang or not mw.language.isKnownLanguageTag(lang) then
lang = frame:callParserFunction( "int", "lang" ) -- get user's chosen language
lang = frame:callParserFunction( "int", "lang" ) -- get user's chosen language
end
-- add text of invisible tag brodcasted by the template which allows creation of QuickStatements command used to add this info to Wikidata
local labels = ''
if args.add_labels then
labels = add_labels(args)
end
end
Line 120: Line 100:
local val = p._langSwitch(args, lang)
local val = p._langSwitch(args, lang)
if val then
if val then
return val .. labels
return val
end
end
Line 133: Line 113:
end
end
end
end
return p._langSwitch(args1, lang) .. labels
return p._langSwitch(args1, lang)
end
end