모듈:Language with name/for

--=nocat=
	
basic rendering
	 ( for )
multiple terms
	 ( for  /  / )
paren=none
	  for 
break=yes
	( for )
italic-term=yes
	 ( for  /  / )
lang-name=
	 ( for )
**
require ('strict');
local get_args = require ('Module:Arguments').getArgs;
local lang_mod = require ('Module:Lang');
--------------------------------------------------------------------------------
render an error message with help-text link and category.
local function error_message (message)
	local err_msg_t = {'Error: : '};		-- open span and initial bit of the error message
	table.insert (err_msg_t, message);											-- the rest of the message
	table.insert (err_msg_t, ' (help)');	-- the help link
	local namespace = mw.title.getCurrentTitle().namespace;						-- namespace number
	if 0 == namespace or 10 == namespace then
		table.insert (err_msg_t, );	-- categorize in main and template namespaces
	end
	return table.concat (err_msg_t);											-- make a big string and done
end
--itlaic-term=yes
local function terms_get (args_t)
	local function render_term (term, is_italic)								-- local function to do the rendering
		if is_italic then
			term = term:gsub ('.+', '%1');								-- apply italic markup; html to avoid converting  to  when quoted
		end
		if is_italic or term:match ('^\'\'\'$') then
			term = term:gsub ('.+', %1);
		else
			term = term:gsub ('.+', %1);								-- quote using ' in case term uses italic or bold wikimarkup
		end
		return term;															-- done this was to avoid second string.gsub() return value
	end
	local is_italic = 'yes' == args_t'italic-term';							-- make boolean
	
	if args_t3 then															-- if  has a value
		return render_term (args_t3, is_italic);
	end
	
	local terms = {};															-- a table to hold one or more non-English terms
	
	for k, v in pairs (args_t) do
		if 'string' == type (k) and k:match ('term%d') then						-- string parameter names only
			table.insert (terms, k:match ('term(%d+)') .. '=' .. v);			-- convert k/v pairs to a sequence that can be sorted by |termn= enumerator (enum=term)
		end
	end
	
	table.sort (terms, function (a, b)											-- sort the sequence using local sort function
		local enum_a = a:match ('^%d+');										-- make numbers for the comparison
		local enum_b = b:match ('^%d+');
		return tonumber(enum_a) ------------------------------------------------------------
if  has a value (the non-English text) use  to apply proper html markup.  When |lang-name= has a
value, override any value that might be in  with 'mis' (uncoded languages) 
TODO: error condition when both of  and |lang-name= have values?
local function text_make (lang_params_t)
	if not lang_params_t2 then
		return ;
	end
	return lang_mod._lang (lang_params_t);
end
--links=no
local function lang_make (args_t, lang_params_t)
	if args_t'lang-name' then
		if 'no' == args_t.links then
			return args_t'lang-name';
		end
		
		local lang_t = {};														-- holds component parts of language name link when using |lang-name=
		table.insert (lang_t, );											-- open wikilink
		table.insert (lang_t, args_t'lang-name');								-- add the name from |lang-name=
		table.insert (lang_t, ' language|');									-- add ' languge' for redirect and pipe for link label
		table.insert (lang_t, args_t'lang-name');								-- add language name as label for wikilink
		table.insert (lang_t, );											-- close wikilink
		return table.concat (lang_t);											-- and make a big string and done
	end
		
	return lang_mod._name_from_tag (lang_params_t);								-- get language name (linked or not) from fn=name_from_tag
end
--------------------------------------------------------------------------------------------
entry point from another module
local function _langnf (args_t)
	if not (args_t1 or args_t'lang-name') then
		return error_message ('missing language tag or language name');
	end
	if (args_t1 and args_t'lang-name') then
		return error_message ('only one of  and |lang-name= allowed');
	end
	if not (args_t3 or args_t.term1) then
		return error_message ('missing English translation');
	end
	local lang_params_t = {														-- build a table of parameters to be used by 
		link = args_t.links or 'yes', 'rtl'=args_t.rtl,						-- used by fn=tag_from_name
		1 = args_t'lang-name' and 'mis' or args_t1,						-- used by  and by fn=tag_from_name
		2 = args_t2,														-- the rest of these are  parameters used only by 
		rtl = args_t.rtl,														-- right-to-left; not normally needed
		i = args_t.i,															-- |italic= alias
		italic = args_t.italic,
		italics = args_t.italics,												-- |italic= alias
		size = args_t.size,
		cat = args_t.cat,
		nocat = args_t.nocat,
		template = 'Language with name/for',
		}
	local out_t = {};															-- components of the rendering go here
	local left_paren = ('none' == args_t.paren or 'right' == args_t.paren) and  or '(';
	local right_paren = (not args_t2 or 'none' == args_t2 or 'left' == args_t.paren or 'none' == args_t.paren) and  or ')';
	
	if args_t2 and ('none' ~= args_t2) then									-- optional;   may be omitted; keyword 'none' prevents categorization; used in 
		table.insert (out_t, text_make (lang_params_t));						-- the non-English text marked up by 
		table.insert (out_t, 'yes' == args_t'break' and  or ' ');		--  when |break=yes;  else
		table.insert (out_t, left_paren);										-- omit left paren around ' for ' when |paren=none or |paren=right
	end
	table.insert (out_t, lang_make (args_t, lang_params_t));					-- language name; linked unless |links=no
	table.insert (out_t, ' for ');												-- the 'for' static text
	table.insert (out_t, terms_get (args_t));									-- and the term(s) italicized as appropriate and quoted
	table.insert (out_t, right_paren);											-- omit right paren around ' for ' when |paren=none or |paren=left or  omitted
	
	if not args_t2 then														-- if this template doesn't use  for the non-English text
		table.insert (out_t, );	-- add this category
	end
	
	return table.concat (out_t);												-- make a big string and done
end
----------------------------------------------------------------------------------------------
implements 
local function langnf (frame)
	local args_t = get_args (frame);
	return _langnf (args_t)
end
--------------------------------------------------------------------------------------------
return {
	langnf = langnf,															-- entry point from a template
	
	_langnf = _langnf,															-- entry point from another module
	}