Jump to content

Module:Infobox multi-lingual name

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Trappist the monk (talk | contribs) at 19:41, 29 December 2018 (create;). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local label_map = {
	['bp'] = '[[Bbánlám pìngyīm|Bbánlám Pìngyīm]]',
	['bpmf'] = '[[Bopomofo]]',
	['gan'] = '[[Gan Chinese|Gan]]',
	['h'] = '[[Guangdong Romanization#Hakka|Hakka]]',
	['hsn'] = '[[Xiang Chinese|Xiang]]',
	['j'] = '[[Cantonese]] [[Jyutping]]',
	['jy'] = '[[Jyutping]]',													-- for |showflag=[jy | yj ] ???? why different from 'j'?
	['lmz'] = '[[Shanghainese]]<br />[[Long-short (romanization)|Romanization]]',	-- ???? why the line break?
	['p'] = '[[Hanyu Pinyin]]',
	['phfs'] = '[[Pha̍k-fa-sṳ]]',
	['poj'] = '[[Hokkien]] [[Pe̍h-ōe-jī|POJ]]',
	['psic'] = '[[Sichuanese Mandarin|Sichuanese]] [[Sichuanese Pinyin|Pinyin]]',
	['tl'] = '[[Taiwanese Romanization System|Tâi-lô]]',
	['toi'] = '[[Taishanese]] [[Jyutping]]',
	['w'] = '[[Wade–Giles]]',
	['wuu'] = '[[Wu Chinese|Wu]]',
	['xej'] = '[[Xiao\'erjing]]',
	['y'] = '[[Cantonese]] [[Yale romanization of Cantonese|Yale]]',
	}


--[[--------------------------< T R A N S L _ M A P >----------------------------------------------------------

Table to map |showflags= value to an index into label_map for child infobox |labeln= value and to map |showflags=
vale to the correct parameter for use in child infobox |datan= paramter

]]

local transl_map = {															-- maps |showflag= value to label from label_map table and data from matching parameter name
	['bp'] = {['label1'] = 'bp', ['data1'] = 'bp'},
	['bpmf'] = {['label1'] = 'bpmf', ['data1'] = 'bpmf'},
	['gan'] = {['label1'] = 'gan', ['data1'] = 'gan'},
	['gdp'] = {['label1'] = 'y', ['data1'] = 'y', ['label2'] = 'p', ['data2'] = 'p'},
	['h'] = {['label1'] = 'h', ['data1'] = 'h'},
	['hsn'] = {['label1'] = 'hsn', ['data1'] = 'hsn'},
	['j'] = {['label1'] = 'j', ['data1'] = 'j'},
	['jp'] = {
		['label1'] = 'y',
		['data1'] = 'y',																		-- index into pframe.args['y']
		['label2'] = 'p',
		['data2'] = 'p'
		},
	['jy'] = {
		['label1'] = 'jy',		-- why is this not the same as 'j'?
		['data1'] = 'j',
		['label2'] = 'y',
		['data2'] = 'y'
		},
	['jyp'] = {['label1'] = 'y', ['data1'] = 'y', ['label2'] = 'j', ['data2'] = 'j', ['label3'] = 'p', ['data3'] = 'p'},
	['lmz'] = {['label1'] = 'lmz', ['data1'] = 'lmz'},
	['p'] = {['label1'] = 'p', ['data1'] = 'p'},
	['phfs'] = {['label1'] = 'phfs', ['data1'] = 'phfs'},
	['phsn'] = {['label1'] = 'p', ['data1'] = 'p', ['label2'] = 'hsn', ['data2'] = 'hsn'},
	['pj'] = {['label1'] = 'p', ['data1'] = 'p', ['label2'] = 'j', ['data2'] = 'j'},
	['poj'] = {['label1'] = 'poj', ['data1'] = 'poj'},
	['psic'] = {['label1'] = 'p', ['data1'] = 'p', ['label2'] = 'sic', ['data2'] = 'sic'},
	['pwuu'] = {['label1'] = 'p', ['data1'] = 'p', ['label2'] = 'wuu', ['data2'] = 'wuu'},
	['py'] = {['label1'] = 'p', ['data1'] = 'p', ['label2'] = 'y', ['data2'] = 'y'},
	['tl'] = {['label1'] = 'tl', ['data1'] = 'tl'},
	['toip'] = {['label1'] = 'toi', ['data1'] = 'toi', ['label2'] = 'p', ['data2'] = 'p'},
	['wp'] = {['label1'] = 'w', ['data1'] = 'w', ['label2'] = 'p', ['data2'] = 'p'},
	['wuu'] = {['label1'] = 'wuu', ['data1'] = 'wuu'},
	['y'] = {['label1'] = 'y', ['data1'] = 'y'},
	['yj'] = {['label1'] = 'y', ['data1'] = 'y', ['label2'] = 'jy', ['data2'] = 'j'},
	['xej'] = {
		['label1'] = 'xej',
		['data1'] = 'xej',				-- ???? what to do about this; template calls {{lang|zh-Arab|{{{xej}}}}} on this value
		},
	['xejp'] = {
		['label1'] = 'xej',
		['data1'] = 'xej',				-- ???? template does not call {{lang|zh-Arab|{{{xej}}}}} on this value; why?
		['label2'] = 'p',
		['data2'] = 'p'
		},
	}


--[[--------------------------< S H O W F L A G >--------------------------------------------------------------

This function handles the |showflags= parameter from the template {{Infobox Chinese}}.  That template passes the
value to {{Infobox Chinese/Chinese}} which {{#invoke:}}s this module/function.  This function does not take any
frame parameters.  All parameter used by this function come from the {{Infobox Chinese/Chinese}} template parent
frame.

This function returns a child infobox or an empty string

{{#invoke:Module:Sandbox/trappist_the_monk/Ibox_zh|showflag}}

]]

local function showflag (frame)
	local pframe = frame:getParent();											-- there are no frame arguments for this function; all arguments must come from the parent (the template)
	local show_flag = pframe.args.showflag; 
	
	if (show_flag and '' ~= show_flag) or not show_flag then
		return '';																-- |showflag= not set so nothing to do; return empty string
	end

	local infobox_args = {};													-- table to hold arguments for frame:expandTemplate()
	
	infobox_args['child'] = 'yes';												-- showflag infoboen are always children
	infobox_args['labelstyle'] = 'font-weight:normal';							-- and always have this label style
	
	
	if transl_map[show_flag] then
		local i=1;
		while (1) do
			local label = 'label' .. i;											-- make label index that matches |labeln= parameter 
			local data = 'data' .. i;											-- make data index that matches |datan= parameter 
			if not transl_map[show_flag].label then
				break;															-- not found then done
			end
			infobox_args.label = label_map[transl_map[show_flag].label];		-- add |labeln=<label text / wikilink>
			infobox_args.data = frame.args[transl_map[show_flag].data];			-- add |datan={{{data}}}
			i = i + 1;															-- bump to next label / data pair
		end
	else
		return '';																-- |showflag= value invlaid; TODO: return error message?
	end
	
	return frame:expandTemplate ({title='Infobox', args = infobox_args});
	end


--[[--------------------------< E X P O R T E D   F U N C T I O N S >------------------------------------------
]]

return {
	showflag = showflag,
	}