Module:LangSwitch: Difference between revisions
From Test Wiki
Content deleted Content added
m 1 revision imported: Import of templates from Wikimedia Commons under license CC BY SA 3.0 |
per edit request |
||
| 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(' |
require('strict') |
||
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 94: | Line 108: | ||
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 100: | Line 120: | ||
local val = p._langSwitch(args, lang) |
local val = p._langSwitch(args, lang) |
||
if val then |
if val then |
||
return val |
return val .. labels |
||
end |
end |
||
| Line 113: | Line 133: | ||
end |
end |
||
end |
end |
||
return p._langSwitch(args1, lang) |
return p._langSwitch(args1, lang) .. labels |
||
end |
end |
||