Module:Description: Difference between revisions
From Neodyland Wiki
More actions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
--[[ | |||
__ __ _ _ ____ _ _ _ | |||
| \/ | ___ __| |_ _| | ___ _| _ \ ___ ___ ___ _ __(_)_ __ | |_(_) ___ _ __ | |||
| |\/| |/ _ \ / _` | | | | |/ _ (_) | | |/ _ \/ __|/ __| '__| | '_ \| __| |/ _ \| '_ \ | |||
| | | | (_) | (_| | |_| | | __/_| |_| | __/\__ \ (__| | | | |_) | |_| | (_) | | | | | |||
|_| |_|\___/ \__,_|\__,_|_|\___(_)____/ \___||___/\___|_| |_| .__/ \__|_|\___/|_| |_| | |||
|_| | |||
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 core = require('Module:Core') | ||
local p = {} | local p = {} | ||
function p | function p.langWrapper(text, textLang, inline) | ||
-- code equivalent to https://commons.wikimedia.org/wiki/Template:Description | -- code equivalent to https://commons.wikimedia.org/wiki/Template:Description | ||
local wordsep = mw.message.new( "Word-separator" ):inLanguage(textLang):plain() | |||
local LangName = mw.language.fetchLanguageName( textLang, textLang) | local LangName = mw.language.fetchLanguageName( textLang, textLang) | ||
local language = mw.language.new( textLang ) | local language = mw.language.new( textLang ) | ||
| Line 9: | Line 25: | ||
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('display:inline' and inline or nil) | :cssText('display:inline' and core.yesno(inline) or nil) | ||
:tag('b') -- make it bold | :tag('b') -- make it bold | ||
:wikitext(language:ucfirst(LangName)..':') | :wikitext(language:ucfirst(LangName)..':') | ||
| Line 19: | Line 35: | ||
:attr('dir', dir) | :attr('dir', dir) | ||
:attr('lang', textLang) | :attr('lang', textLang) | ||
:wikitext(tostring(ltag)..text) | :wikitext(tostring(ltag) .. wordsep .. text) | ||
return tostring(dtag) | return tostring(dtag) | ||
end | end | ||
function p | function p.description(frame) | ||
local args = core.getArgs(frame) | local args = core.getArgs(frame) | ||
local desc = p | 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 | 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) | local msg = core.formatMessage('I18n/DescriptionError.tab', 'missing text', lang) | ||
msg = mw.html.create('span'):addClass("error"):wikitext(msg) | msg = mw.html.create('span'):addClass("error"):wikitext(msg) | ||
msg = '[{{fullurl: | msg = '[{{fullurl:' .. cat .. '}} ' .. tostring(msg) .. ']' | ||
msg = mw.html.create('span'):addClass("plainlinks"):wikitext(msg) | msg = mw.html.create('span'):addClass("plainlinks"):wikitext(msg) | ||
desc = desc.. | 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 | end | ||
return desc | return desc | ||
Revision as of 23:27, 26 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 = {}
function p.langWrapper(text, textLang, inline)
-- code equivalent to https://commons.wikimedia.org/wiki/Template:Description
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('display:inline' and core.yesno(inline) or nil)
:tag('b') -- make it bold
:wikitext(language:ucfirst(LangName)..':')
-- mw-content-rtl and mw-content-ltr are defined in (?)
-- https://gerrit.wikimedia.org/g/mediawiki/core/+/3825c4d04d9d9701ac04bb3bc6a2f2ca43253d10/resources/src/mediawiki.skinning/content.css
local dtag = mw.html.create('div')
:addClass("description mw-content-"..dir) -- div.description is tracked by mw:Extension:CommonsMetadata
: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