Modulo:Lang/documentor tool

Dokumentasion ti modulo

Panagusar

urnosen

Kitaen pay

urnosen

require('strict');
local p = {};

--[[-------------------------< L A N G - X X _ S E T T I N G S >-----------------------------------------------

{{#invoke:Lang/documentor tool|lang_xx_settings|template={{ROOTPAGENAME}}}}

reads the content of the template and extracts the parameters from {{#invoke:Lang|...}} for display on the template's
documentation page

]]

function p.lang_xx_settings (frame)
	local page = mw.title.makeTitle ('Plantilia', frame.args['template'] or frame.args[1]);	-- get a page object for this page in 'Template:' namespace
	if not page then
		return '';																-- TODO: error message?
	end
	
	local content = page:getContent();											-- get unparsed content
	if not page then
		return '';																-- TODO: error message?
	end

	local out = {};
	
	local params;
	local style;

	if content:match ('{{%s*#invoke:%s*[Ll]ang%s*|[^|]+|[^}]+}}') or content:match ('{{%s*#invoke:%s*[Ll]ang/pagipadasan%s*|[^|]+|[^}]+}}') then			-- if this template uses [[Module:Lang]]
		params = content:match ('{{%s*#invoke:%s*[Ll]ang%s*|[^|]+(|[^}]+)}}') or content:match ('{{%s*#invoke:%s*[Ll]ang/pagipadasan%s*|[^|]+(|[^}]+)}}')	-- extract the #invoke:'s parameters
		if not params then 
			return '';															-- there should be at least one or the template/module won't work TODO: error message?
		end
		table.insert (out, '{| class="wikitable" style="text-align:right; float:right"\n|+settings')	-- start a wikitable
		for k, v in params:gmatch ('%s*|%s*([^%s=]+)%s*=%s*([^%s|]+)') do		-- get the parameter names (k) and values (v)
			if 'label' == k then												-- special case for labels because spaces and pipes
				v = params:match ('label%s*=%s*(%[%[[^%]]+%]%])') or params:match ('label%s*=%s*([^|\n]+)') or 'missing label';
			end
			table.insert (out, table.concat ({k, '\n|', v}));					-- make rudimentary wikitable entries
		end

		style = content:match ('lang_xx_([^|]+)');
		return table.concat ({table.concat (out,'\n|-\n! scope="row" | '), '\n|-\n|colspan="2"|style: ', style, '\n|-\n|}'});	-- add inter-row markup and close the wikitable and done
	else
		return '';																-- does not use [[Module:Lang]] so abandon quietly
	end
end


--[[-------------------------< U S E S _ M O D U L E >---------------------------------------------------------

{{#invoke:Lang/documentor tool|uses_module|template={{ROOTPAGENAME}}}}

reads the content of the template to determine if this {{lang-xx}} template uses Module:Lang.  Returns the index
of the substring '{{#invoke|lang|' in the template page content if true; empty string if false

Used in template documentation {{#if:}} parser functions.

]]

function p.uses_module (frame)
	local page = mw.title.makeTitle ('Plantilia', frame.args['template'] or frame.args[1]);	-- get a page object for this page in 'Template:' namespace
	if not page then
		return '';																-- TODO: error message?
	end
	
	local content = page:getContent();											-- get unparsed content
	if not page then
		return '';																-- TODO: error message?
	end
	
	return content:find ('{{%s*#invoke:[Ll]ang%s*|') or '';						-- return index or empty string
end


--[[--------------------------< N O N _ I L O _ S R C _ C A T >--------------------------------------------------

this function implements most of {{Kategoria ti taudan ti saan a pagsasao nga Ilokano}}

{{#invoke:lang/documentor tool|non_ilo_src_cat|{{{1|}}}}} - where {{{1|}}} is language code

]]

function p.non_ilo_src_cat (frame)
	local lang_code = frame.args[1]:match ('%(([%a%-]+)%)');					-- frame.args[1] is category page name; extract language code from that
	local lang_name = require ('Modulo:Lang')._name_from_tag ({lang_code});		-- get language name from language code in cat name via Module:lang
	local out = {};																-- bits of the output go here

	table.insert (out, 'Daytoy ti pagsurotan a kategoria para kadagiti artikulo nga agus-usar iti ');	-- static text
	table.insert (out, frame:preprocess ('{{tlx|iti sao|' .. lang_code .. '}}'));	-- preprocess
	table.insert (out, ' tapno mailasin dagiti taudan iti ');						-- more static text

	if lang_name:find ('sasao') then										    -- is a language collective?
		table.insert (out, 'kolektibo a [[' .. lang_name .. ']]');			    -- say so
	else
		table.insert (out, '[[pagsasao ' ..frame:expandTemplate{ title = 'Plantilia:a wenno nga', args = {lang_name} }.. ']].');
	end


	local cat_art = mw.title.new ('Kategoria:Dagiti artikulo nga aglaon iti teksto ti pagsasao ' ..frame:expandTemplate{ title = 'Plantilia:a wenno nga', args = {lang_name} }).exists;
	local cat_with = mw.title.new ('Kategoria:Dagiti artikulo nga aglaon kadagiti akinruar a silpo ti pagsasao ' ..frame:expandTemplate{ title = 'Plantilia:a wenno nga', args = {lang_name} }).exists;		-- TODO: delete this because the cat will go away when {{xx icon}} templates replaced
	local cat_cs1 = mw.title.new ('Kategoria:Dagiti taudan ti pagsasao ti CS1 iti ' .. lang_name .. ' (' .. lang_code .. ')').exists;

	if cat_art or cat_with or cat_cs1 then
		table.insert (out, '\n\n==Kitaen pay==');									-- start see also section
		if cat_art then
			table.insert (out, '\n*[[:Kategoria:Dagiti artikulo nga aglaon iti teksto ti pagsasao ' ..frame:expandTemplate{ title = 'Plantilia:a wenno nga', args = {lang_name} }..']]');
		end
		if cat_with then
			table.insert (out, '\n*[[:Kategoria:Dagiti artikulo nga aglaon kadagiti akinruar a silpo ti pagsasao ' ..frame:expandTemplate{ title = 'Plantilia:a wenno nga', args = {lang_name} }..']]');		-- TODO: delete this because the cat will go away
		end
		if cat_cs1 then
			table.insert (out, '\n*[[:Kategoria:Dagiti taudan ti pagsasao ti CS1 iti ' .. lang_name .. ' (' .. lang_code .. ')]]');
		end
	end
	table.insert (out, '[[Kategoria:Dagiti artikulo nga agraman kadagiti taudan ti saan a pagsasao nga Ilokano|' .. lang_code .. ']]')				-- and categorize this category; language code sortkey
	return table.concat (out);													-- string it all together and done
end

return p;