「モジュール:LangSwitch」の版間の差分
ナビゲーションに移動
検索に移動
add "add_label" parameter for adding invisible but machine-readable labels if needed
細 (1版 をインポートしました) |
bsd>Jarekt (add "add_label" parameter for adding invisible but machine-readable labels if needed) |
||
16行目: | 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 | |||
--[[ | --[[ | ||
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 |