Module:LangSwitch: Difference between revisions
Jump to navigation
Jump to search
Richardpruen (talk | contribs) m (1 revision imported) |
mediawiki>Jarekt (add "add_label" parameter for adding invisible but machine-readable labels if needed) |
||
Line 16: | Line 16: | ||
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 | ||
return p | return p |