Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Description: Difference between revisions

From Neodyland Wiki
No edit summary
No edit summary
Line 22: Line 22:
Code equivalent to https://commons.wikimedia.org/wiki/Template:Description  
Code equivalent to https://commons.wikimedia.org/wiki/Template:Description  
Inputs:
Inputs:
   1) text - description text to display
   1) text_lang - language code for the above text, also used as a name of the CSS formating class
  2) text_lang - language code for the above text, also used as a name of the CSS formating class
  2) text - description text to display
   3) args -  additional optional arguments
   3) args -  additional optional arguments. Numbers in perenthesis are parameter numbers in the original template.
  * hover    - (3) hover aka mouseover aka tooltip text
  * lang_tag - (4) standard code for lang tag in HTML (optional, default is same as text_lang)
  * ext      - (5) extension text shown after the language name before colon (optional, default is empty)
       * inline - Optional, default is false. When set to true, forces the template to be displayed  
       * inline - Optional, default is false. When set to true, forces the template to be displayed  
             inline, so that it does not break the current paragraph (that makes possible to put several  
             inline, so that it does not break the current paragraph (that makes possible to put several  
        descriptions side by side on a single line)
        descriptions side by side on a single line)
  * ext - extension text shown after the language name before colon (optional, default is empty)
  * haver -  hover aka mouseover aka tooltip text
  * disp_lang -  
  * disp_lang -  
  * user_lang - language code of the users language (used for the hover aka mouseover aka tooltip text)  
  * user_lang - language code of the users language (used for the hover aka mouseover aka tooltip text)  
      if args.hover is not provided (defaults to    
      if args.hover is not provided (defaults to
 
<div
class="description mw-content-{{Dir|{{{4|{{{1}}}}}}}} {{{1}}}"
dir="{{Dir|{{{4|{{{1}}}}}}}}"
lang="{{{4|{{{1}}}}}}"
style="{{#if:{{{inline|}}}|display:inline;}}">
 
<span
class="language {{{1}}}"
title="{{{name|{{{3|}}}}}}">'''{{ucfirst:{{#language:{{{1}}}}}}}{{{5|}}}:'''</span>
{{{2}}}
</div>    
]]
]]
function p.langWrapper(text, text_lang, args)  
function p.langWrapper(text_lang, text, args)  
local dir, space, colon, lang_name, hover
local inline    = core.yesno(args.inline, false) and 'inline' or nil  
local inline    = core.yesno(args.inline, false) and 'inline' or nil  
local disp_lang = args.disp_lang and args.disp_lang or text_lang -- disp_lang same as text_lang by default
if mw.language.isKnownLanguageTag(text_lang) then
local user_lang = args.user_lang and args.user_lang or disp_lang -- user_lang is used for the hover text
local langObj = mw.language.new( disp_lang )
local langObj   = mw.language.new( disp_lang )
dir      = langObj:getDir()          -- text direction
local dir      = langObj:getDir()          -- text direction
space    = mw.message.new( "Word-separator" ):inLanguage(text_lang):plain()  
local space    = mw.message.new( "Word-separator" ):inLanguage(disp_lang):plain()  
colon    = mw.message.new( "Colon" ):inLanguage(text_lang):plain()  
local colon    = mw.message.new( "Colon" ):inLanguage(disp_lang):plain()  
lang_name = langObj:ucfirst(mw.language.fetchLanguageName(text_lang, text_lang))
local lang_name = langObj:ucfirst(mw.language.fetchLanguageName(text_lang, disp_lang))
hover    = mw.language.fetchLanguageName( text_lang, args.user_lang or 'en')
local hover    = args.hover and args.hover or mw.language.fetchLanguageName( text_lang, user_lang)
else
dir  = 'ltr'
space = ' '
colon = ':'
text_lang = nil
lang_name = args.lang_name
end
lang_name = '<b>' .. lang_name .. (args.ext or '') .. colon .. '</b>'
lang_name = '<b>' .. lang_name .. (args.ext or '') .. colon .. '</b>'
Line 57: Line 78:
:addClass(text_lang)          -- not sure where "en", "de" etc. are defined
:addClass(text_lang)          -- not sure where "en", "de" etc. are defined
:attr('dir', dir)
:attr('dir', dir)
:attr('lang', disp_lang)
:attr('lang', text_lang)
:css('display', inline)  
:css('display', inline)  
:wikitext(tostring(ltag) .. space .. text)
:wikitext(tostring(ltag) .. space .. text)
Line 67: Line 88:
local args = core.getArgs(frame)
local args = core.getArgs(frame)
local desc
local desc
args.user_lang = args.lang
args.user_lang = args.user_lang or args.lang
args.inline    = (args.inline ~= nil) -- convert to boolean
args.inline    = (args.inline ~= nil) -- convert to boolean
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
-- <span class="plainlinks">[{{fullurl:Category:Language templates with no text displayed}} <span class="error">{{Description/i18n}}</span>]</span>
local cat = 'Category:Language templates with no text displayed'
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)
Line 75: Line 97:
msg = '[' .. frame:callParserFunction{ name = 'fullurl', args={cat} }  .. tostring(msg) .. ']'
msg = '[' .. frame:callParserFunction{ name = 'fullurl', args={cat} }  .. tostring(msg) .. ']'
msg = mw.html.create('span'):addClass("plainlinks"):wikitext(msg)
msg = mw.html.create('span'):addClass("plainlinks"):wikitext(msg)
desc = p.langWrapper(tostring(msg), args.lang, args)
desc = p.langWrapper(args.lang, tostring(msg), args)
local namespace = mw.title.getCurrentTitle().namespace
local namespace = mw.title.getCurrentTitle().namespace
local LUT = {[0]=1, [6]=1, [10]=1, [14]=1, [100]=1, [106]=1}
local LUT = {[0]=1, [6]=1, [10]=1, [14]=1, [100]=1, [106]=1}
Line 82: Line 104:
end
end
else
else
desc = p.langWrapper(args.text, args.lang, args)
desc = p.langWrapper(args.lang, args.text, args)
end
end
return desc
return desc
Line 88: Line 110:


return p
return p
--[[
Oddballs:
 
]]

Revision as of 04:44, 4 March 2021

Module documentation[ create · purge ]
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 
Inputs:
  1) text_lang - language code for the above text, also used as a name of the CSS formating class
  2) text - description text to display
  3) args -  additional optional arguments. Numbers in perenthesis are parameter numbers in the original template.
	   * hover    - (3) hover aka mouseover aka tooltip text
	   * lang_tag - (4) standard code for lang tag in HTML (optional, default is same as text_lang)
	   * ext      - (5) extension text shown after the language name before colon (optional, default is empty)
       * inline - Optional, default is false. When set to true, forces the template to be displayed 
            inline, so that it does not break the current paragraph (that makes possible to put several 
	        descriptions side by side on a single line)
	   * disp_lang - 
	   * user_lang - language code of the users language (used for the hover aka mouseover aka tooltip text) 
	       if args.hover is not provided (defaults to 	

<div 
	class="description mw-content-{{Dir|{{{4|{{{1}}}}}}}} {{{1}}}" 
	dir="{{Dir|{{{4|{{{1}}}}}}}}" 
	lang="{{{4|{{{1}}}}}}" 
	style="{{#if:{{{inline|}}}|display:inline;}}">

	<span 
		class="language {{{1}}}" 
		title="{{{name|{{{3|}}}}}}">'''{{ucfirst:{{#language:{{{1}}}}}}}{{{5|}}}:'''</span> 
		
	{{{2}}}
</div>		   
]]
function p.langWrapper(text_lang, text, args) 
	local dir, space, colon, lang_name, hover
	local inline    = core.yesno(args.inline, false) and 'inline' or nil 
	if 	mw.language.isKnownLanguageTag(text_lang) then
		local langObj = mw.language.new( disp_lang )
		dir       = langObj:getDir()          -- text direction
		space     = mw.message.new( "Word-separator" ):inLanguage(text_lang):plain() 
		colon     = mw.message.new( "Colon" ):inLanguage(text_lang):plain() 
		lang_name = langObj:ucfirst(mw.language.fetchLanguageName(text_lang, text_lang))
		hover     = mw.language.fetchLanguageName( text_lang, args.user_lang or 'en')
	else
		dir   = 'ltr'
		space = ' '
		colon = ':'
		text_lang = nil
		lang_name = args.lang_name
	end
	lang_name = '<b>' .. lang_name .. (args.ext or '') .. colon .. '</b>'
	
	-- create HTML
	local ltag = mw.html.create('span')  -- bold language name string
		:addClass('language')  -- class: "language" 
		:addClass(text_lang)   -- class:  "en", "de" etc.	
		:attr('title', hover)  -- add hover aka mouseover aka tooltip text
		:wikitext(lang_name)
	local dtag = mw.html.create('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(text_lang)          -- not sure where "en", "de" etc. are defined
		:attr('dir', dir)
		:attr('lang', text_lang)
		:css('display', inline) 
		:wikitext(tostring(ltag) .. space .. text)
	return tostring(dtag)
end


function p.description(frame) 
	local args = core.getArgs(frame)
	local desc
	args.user_lang = args.user_lang or args.lang
	args.inline    = (args.inline ~= nil) -- convert to boolean
	if args.text == nil then -- if no string than add error message and a category
		-- <span class="plainlinks">[{{fullurl:Category:Language templates with no text displayed}} <span class="error">{{Description/i18n}}</span>]</span>
		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 = '[' .. frame:callParserFunction{ name = 'fullurl', args={cat} }  .. tostring(msg) .. ']'
		msg = mw.html.create('span'):addClass("plainlinks"):wikitext(msg)
		desc = p.langWrapper(args.lang, tostring(msg), args)
		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
	else
		desc = p.langWrapper(args.lang, args.text, args)
	end
	return desc
end

return p

--[[
Oddballs:
   
]]
Cookies help us deliver our services. By using our services, you agree to our use of cookies.