Module:Description: Difference between revisions
From Neodyland Wiki
More actions
No edit summary |
No edit summary |
||
| Line 17: | Line 17: | ||
local p = {} | local p = {} | ||
------------------------------------------------------------------------------ | |||
--[[ | |||
display a language followed by a message. Like "English: Hello" with extensive HTML marking | |||
Code equivalent to https://commons.wikimedia.org/wiki/Template:Description with only 3 inputs | |||
Inputs: | |||
1) text - text to display | |||
2) textLang - langiage code for the above text | |||
3) inline - | |||
]] | |||
function p.langWrapper(text, textLang, inline) | function p.langWrapper(text, textLang, inline) | ||
local wordsep = mw.message.new( "Word-separator" ):inLanguage(textLang):plain() | local wordsep = mw.message.new( "Word-separator" ):inLanguage(textLang):plain() | ||
local LangName = mw.language.fetchLanguageName( textLang, textLang) | local LangName = mw.language.fetchLanguageName( textLang, textLang) | ||
| Line 25: | Line 33: | ||
local ltag = mw.html.create('span') -- bold language name string | local ltag = mw.html.create('span') -- bold language name string | ||
:addClass('language '..textLang) -- classes: "language" and "en", "de" etc. | :addClass('language '..textLang) -- classes: "language" and "en", "de" etc. | ||
:cssText(core.yesno(inline) and 'display:inline' or nil) | :cssText((inline==1) and 'display:inline' or nil) | ||
--:cssText(core.yesno(inline) and 'display:inline' or nil) | |||
:wikitext('<b>' .. language:ucfirst(LangName)..':</b>') | :wikitext('<b>' .. language:ucfirst(LangName)..':</b>') | ||
local dtag = mw.html.create((inline==2) and 'span' or 'div') | |||
:addClass('description') -- div.description is tracked by mw:Extension:CommonsMetadata | |||
local dtag = mw.html.create('div') | :addClass('mw-content-'..dir) -- mw-content-rtl and mw-content-ltr are defined in mediawiki-code (https://gerrit.wikimedia.org/r/c/mediawiki/core/+/208332) | ||
:addClass('description') -- div.description is tracked by mw:Extension:CommonsMetadata | :addClass(textLang) -- not sure where "en", "de" etc. are defined | ||
:addClass('mw-content-'..dir) -- | |||
:addClass(textLang) | |||
:attr('dir', dir) | :attr('dir', dir) | ||
:attr('lang', textLang) | :attr('lang', textLang) | ||
Revision as of 02:55, 27 February 2021
This documentation is transcluded from Module:Description/doc.
--[[
__ __ _ _ ____ _ _ _
| \/ | ___ __| |_ _| | ___ _| _ \ ___ ___ ___ _ __(_)_ __ | |_(_) ___ _ __
| |\/| |/ _ \ / _` | | | | |/ _ (_) | | |/ _ \/ __|/ __| '__| | '_ \| __| |/ _ \| '_ \
| | | | (_) | (_| | |_| | | __/_| |_| | __/\__ \ (__| | | | |_) | |_| | (_) | | | |
|_| |_|\___/ \__,_|\__,_|_|\___(_)____/ \___||___/\___|_| |_| .__/ \__|_|\___/|_| |_|
|_|
Description is a module implementing functionality of {{Description}}
template, which is used by {{en}}, {{de}} and other language templates.
Authors and maintainers:
* User:Jarekt
]]
local core = require('Module:Core')
local p = {}
------------------------------------------------------------------------------
--[[
display a language followed by a message. Like "English: Hello" with extensive HTML marking
Code equivalent to https://commons.wikimedia.org/wiki/Template:Description with only 3 inputs
Inputs:
1) text - text to display
2) textLang - langiage code for the above text
3) inline -
]]
function p.langWrapper(text, textLang, inline)
local wordsep = mw.message.new( "Word-separator" ):inLanguage(textLang):plain()
local LangName = mw.language.fetchLanguageName( textLang, textLang)
local language = mw.language.new( textLang )
local dir = language:getDir()
local ltag = mw.html.create('span') -- bold language name string
:addClass('language '..textLang) -- classes: "language" and "en", "de" etc.
:cssText((inline==1) and 'display:inline' or nil)
--:cssText(core.yesno(inline) and 'display:inline' or nil)
:wikitext('<b>' .. language:ucfirst(LangName)..':</b>')
local dtag = mw.html.create((inline==2) and 'span' or 'div')
:addClass('description') -- div.description is tracked by mw:Extension:CommonsMetadata
:addClass('mw-content-'..dir) -- mw-content-rtl and mw-content-ltr are defined in mediawiki-code (https://gerrit.wikimedia.org/r/c/mediawiki/core/+/208332)
:addClass(textLang) -- not sure where "en", "de" etc. are defined
:attr('dir', dir)
:attr('lang', textLang)
:wikitext(tostring(ltag) .. wordsep .. text)
return tostring(dtag)
end
function p.description(frame)
local args = core.getArgs(frame)
local desc = p.langWrapper(args.text, args.lang, args.inline)
if args.text == nil then -- if no string than add error message and a category
local cat = 'Category:Language templates with no text displayed'
local msg = core.formatMessage('I18n/DescriptionError.tab', 'missing text', lang)
msg = mw.html.create('span'):addClass("error"):wikitext(msg)
msg = '[{{fullurl:' .. cat .. '}} ' .. tostring(msg) .. ']'
msg = mw.html.create('span'):addClass("plainlinks"):wikitext(msg)
local desc = p.langWrapper(msg, args.lang, args.inline)
local namespace = mw.title.getCurrentTitle().namespace
local LUT = {[0]=1, [6]=1, [10]=1, [14]=1, [100]=1, [106]=1}
if LUT[namespace]==1 then
desc = desc .. '[[' .. cat .. ']]'
end
end
return desc
end
return p