「モジュール:LangSwitch」の版間の差分

1版 をインポートしました
(1版 をインポートしました)
(1版 をインポートしました)
 
(3人の利用者による、間の3版が非表示)
13行目: 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('Module:No globals')  
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


--[[
--[[
94行目: 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
100行目: 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
113行目: 133行目:
end
end
end
end
return p._langSwitch(args1, lang)
return p._langSwitch(args1, lang) .. labels
end
end


return p
return p