Jump to content

Module:Sandbox/trappist the monk/genitive

From Wikipedia, the free encyclopedia
--[[

assemble a list of language tags from the MediaWiki interwiki map that retun different month names with these
{{#time}} parser function calls:
	{{#time:F|2024-mm-01|ru}} – nominative
	{{#time:xg|2024-mm-01|ru}} – genitive
where 'mm' is a month number (1–12)

{{#invoke:Sandbox/trappist the monk/genitive|main|<alpha_range>}}

<alpha_range> is a simple pattern that identifies the first character of a language tag.  Alas, at the time of
this writing, 2024-11-25, 'a-z' breaks something and {{#time}} returns an error message:
	Error: Total length of format strings for #time exceeds 6000 bytes.

That seems to be nonsense because the actual format strings are 1 and 2 bytes only.

'a-m' and 'n-z' work but not if this module is invoked one right after the other.

mw.language:formatDate() won't work for this application because it does not accept (so far as I can tell from
the documentation) a language parameter; {{#time}} does.

See [Phab:T299909] and especially the linked discussion.  In essence, {{#time}} accumulates length of format
strings for each call on a page.  When that number exceed 6000, {{#time}} returns an error message. So, this
module must be {{#invoke}}d only once per page.

All 12 months of the year must be tested because some languages that have different 'F' and 'xg' month-names also
have same-named months for 'F' and 'xg'.

How to know that the languages discovered by this module really do use 'xg' for genitive dates?

]]

require ('strict')

local iw_t = mw.loadData ('Module:Citation/CS1/Configuration').inter_wiki_map;	-- get a list of interwiki language tags


--[[--------------------------< M A I N >----------------------------------------------------------------------
]]

local function main (frame)
	local lang_has_nom_and_gen_t = {};											-- list of language tags where #time returns different names for nom and gen
	local iw_lang_count = 0;													-- count the total number of language tags from the interwiki list that we look at
	local lang_count = 0;														-- count the total number of language tags we test
	local found_count = 0;														-- count of tags that have different nominative and genitive month names
	local total_fmt_str_len = 0;												-- accumulating length of the format strings
	
	if not frame.args[1] then
		return error ('missing <alpha range>');									-- abandon with error message
	end

	for lang, _ in pairs (iw_t) do
		iw_lang_count = iw_lang_count   1;										-- bump the counter
		if lang:match ('^[' .. frame.args[1] .. ']') then
			lang_count = lang_count   1;										-- bump the counter
			for m=1, 12 do														-- test all 12 months if necessary
				local timestamp = '2024-' .. m .. '-01';						-- make a timestamp

				local month_gen = frame:callParserFunction ({name='#time', args={'xg', timestamp, lang}});	-- get the genitive month name
				total_fmt_str_len = total_fmt_str_len   2;						-- accumulate format string length

				local month_nom = frame:callParserFunction ({name='#time', args={'F', timestamp, lang}});	-- get the nominative month name
				total_fmt_str_len = total_fmt_str_len   1;						-- accumulate format string length

				if month_gen:find ('[Ee]rror') or month_nom:find ('[Ee]rror') then
					error ('error return for tag: ' .. lang .. ': ' .. month_gen .. ' (' .. total_fmt_str_len .. ')');	-- trap an error return
				end

				if month_nom ~= month_gen then									-- not the same then
					table.insert (lang_has_nom_and_gen_t, lang);				-- log the language tag
					found_count = found_count   1;								-- bump the counter
					break;														-- assume that this language has nominative and genitive dating; go do next language
				end
			end
		end
	end

	table.sort (lang_has_nom_and_gen_t);										-- ascending sort
	table.insert (lang_has_nom_and_gen_t, 1, 'found ' .. found_count .. ' of ' .. lang_count .. '/' .. iw_lang_count .. ' (' .. total_fmt_str_len ..')');	-- add a simple header
	return mw.dumpObject (lang_has_nom_and_gen_t);								-- dump the output and done
end


--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]

return {
	main = main,
	}