<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://battleint.net/index.php?action=history&amp;feed=atom&amp;title=Module%3AISBN_RangeMessage_xlate</id>
	<title>Module:ISBN RangeMessage xlate - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://battleint.net/index.php?action=history&amp;feed=atom&amp;title=Module%3AISBN_RangeMessage_xlate"/>
	<link rel="alternate" type="text/html" href="https://battleint.net/index.php?title=Module:ISBN_RangeMessage_xlate&amp;action=history"/>
	<updated>2026-11-20T01:16:15Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://battleint.net/index.php?title=Module:ISBN_RangeMessage_xlate&amp;diff=176719&amp;oldid=prev</id>
		<title>imported&gt;Deadfire: creation</title>
		<link rel="alternate" type="text/html" href="https://battleint.net/index.php?title=Module:ISBN_RangeMessage_xlate&amp;diff=176719&amp;oldid=prev"/>
		<updated>2025-01-12T00:32:33Z</updated>

		<summary type="html">&lt;p&gt;creation&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;require (&amp;#039;strict&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
local title_object = mw.title.getCurrentTitle ();								-- get this module&amp;#039;s title object&lt;br /&gt;
if not title_object.fullText:find (&amp;#039;/doc$&amp;#039;) then								-- are we are looking at the ~/doc page or the module page?&lt;br /&gt;
	local module_doc_title = title_object.fullText .. &amp;#039;/doc&amp;#039;;					-- looking at the module page so make a page name for this module&amp;#039;s doc page&lt;br /&gt;
	title_object = mw.title.new (module_doc_title);								-- reset title object to this module&amp;#039;s doc page&lt;br /&gt;
end&lt;br /&gt;
local range_message_raw = title_object:getContent();							-- get the doc page content&lt;br /&gt;
&lt;br /&gt;
local timestamp_pattern = &amp;#039;&amp;lt;MessageDate&amp;gt;%D+(%d%d? %w%w%w %d%d%d%d %d%d:%d%d:%d%d)( %w%w%w)&amp;lt;/MessageDate&amp;gt;&amp;#039; -- captures are timestamp and time zone (BST or GMT)&lt;br /&gt;
local group_pattern = &amp;#039;&amp;lt;Group&amp;gt;(.-)&amp;lt;/Group&amp;gt;&amp;#039;;									-- capture holds &amp;lt;Prefix&amp;gt;, &amp;lt;Agency&amp;gt;, and &amp;lt;Rules&amp;gt; groups&lt;br /&gt;
local prefix_pattern = &amp;#039;&amp;lt;Prefix&amp;gt;(%d+)%-(%d+)&amp;lt;/Prefix&amp;gt;&amp;#039;;							-- captures are GS1 prefix (978 or 979) and registration group&lt;br /&gt;
local agency_pattern = &amp;#039;&amp;lt;Agency&amp;gt;(.-)&amp;lt;/Agency&amp;gt;&amp;#039;;									-- capture holds language, country, territory&lt;br /&gt;
local rule_pattern = &amp;#039;&amp;lt;Rule&amp;gt;(.-)&amp;lt;/Rule&amp;gt;&amp;#039;;										-- capture holds registrant &amp;lt;Range&amp;gt; and &amp;lt;Length&amp;gt; groups&lt;br /&gt;
local range_pattern = &amp;#039;&amp;lt;Range&amp;gt;(%d+)%-(%d+)&amp;lt;/Range&amp;gt;&amp;#039;;							-- registrant; captures are min and max ranges right-padded to 7 digits; min not currently used&lt;br /&gt;
local length_pattern = &amp;#039;&amp;lt;Length&amp;gt;(%d)&amp;lt;/Length&amp;gt;&amp;#039;;									-- registrant; capture holds number of (left) digits to use from &amp;lt;Range&amp;gt;; for len=2 in max=1299999 -&amp;gt; 12&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; R E N D E R _ O U T P U T &amp;gt;----------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
common function to render either of the two tables that this module creates.  Yeah, requires invoking the module&lt;br /&gt;
twice to get both tables (they are both created each time range_message_xlate() is called), but who cares; it&lt;br /&gt;
only needs to run occasionally.&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function render_output (frame, table_name, out_t, timestamp, timezone, rep)&lt;br /&gt;
	table.insert (out_t, &amp;#039;\t}&amp;lt;/syntaxhighlight&amp;gt;&amp;#039;);								-- to close the table&lt;br /&gt;
	table.insert (out_t, 1, table.concat ({										-- insert this at the start of the output sequence&lt;br /&gt;
		&amp;#039;&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;local &amp;#039; .. table_name .. &amp;#039; = {&amp;#039;,			-- opening stuff&lt;br /&gt;
		string.rep (&amp;#039;\t&amp;#039;, rep),													-- tabs to place the timestamp (15 for hyphen_pos_t, 14 for inverse_range_t)&lt;br /&gt;
		frame:callParserFunction (&amp;#039;#time&amp;#039;, {&amp;#039;-- &amp;quot;RangeMessage timestamp&amp;quot;: Y-m-d&amp;quot;T&amp;quot;h:i:s&amp;#039;, timestamp}),	-- the timestamp&lt;br /&gt;
		timezone																-- and timezone&lt;br /&gt;
		}));&lt;br /&gt;
	return frame:preprocess (table.concat (out_t, &amp;#039;\n&amp;#039;));						-- make a big string and done	&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; R A N G E _ M E S S A G E _ X L A T E &amp;gt;----------------------------------------&lt;br /&gt;
&lt;br /&gt;
{{#invoke:Sandbox/trappist the monk/ISBN RangeMessage xlate|range_message_xlate}}&lt;br /&gt;
&lt;br /&gt;
This function translates a local copy of https://www.isbn-international.org/export_rangemessage.xml for use by&lt;br /&gt;
Module:Format ISBN by way of Module:Format ISBN/data.&lt;br /&gt;
&lt;br /&gt;
To update &amp;lt;hyphen_pos_t&amp;gt; in Module:Format ISBN/data:&lt;br /&gt;
	1. copy the new RangeMessage.xml text from the ISBN international export_rangemessage.xml page (url above) to&lt;br /&gt;
		your clipboard and paste it over the existing xml data inside the html comments in this module&amp;#039;s doc page.&lt;br /&gt;
	2. save.  The new translation is presented on this module&amp;#039;s doc page.&lt;br /&gt;
	3. copy the new translation from the doc page to your clipboard&lt;br /&gt;
	4. edit Module:Format ISBN/data and paste the new &amp;lt;hyphen_pos_t&amp;gt; table over the old&lt;br /&gt;
	5. save&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function range_message_xlate (frame)&lt;br /&gt;
	local out_t = {};															-- the base output goes here (before prettifying)&lt;br /&gt;
	local out_range_t = {}&lt;br /&gt;
	local timestamp, timezone = range_message_raw:match (timestamp_pattern);	-- get the RangeMessage timestamp&lt;br /&gt;
	&lt;br /&gt;
	for group in range_message_raw:gmatch (group_pattern) do					-- get a &amp;lt;Group&amp;gt;...&amp;lt;/Group&amp;gt; block&lt;br /&gt;
		local prefix, registration_group = group:match (prefix_pattern);		-- get the prefix and registration group&lt;br /&gt;
&lt;br /&gt;
		local agency = group:match (agency_pattern);							-- get the &amp;#039;agency&amp;#039;&lt;br /&gt;
		local agency_used = false;												-- flag to for the avoidance of repeats&lt;br /&gt;
		&lt;br /&gt;
		for rule in group:gmatch (rule_pattern) do								-- get a &amp;lt;Rule&amp;gt;...&amp;lt;/Rule&amp;gt; block&lt;br /&gt;
			local isbn_parts_min_t = {};										-- the prefix, registration_group, and registrant, then filled right with &amp;#039;0&amp;#039;s to thirteen digits&lt;br /&gt;
			local isbn_parts_max_t = {};										-- the prefix, registration_group, and registrant, then filled right with &amp;#039;9&amp;#039;s to thirteen digits&lt;br /&gt;
			local element_lengths_t = {};										-- sequence of lengths for registration group, registrant, and publication elements in an isbn&lt;br /&gt;
&lt;br /&gt;
			table.insert (isbn_parts_max_t, prefix);							-- add prefix (1)  This applies to each &amp;lt;Rule&amp;gt; in the &amp;lt;Group&amp;gt;&lt;br /&gt;
			table.insert (isbn_parts_min_t, prefix);							-- add prefix (1)  This applies to each &amp;lt;Rule&amp;gt; in the &amp;lt;Group&amp;gt;&lt;br /&gt;
			&lt;br /&gt;
			table.insert (isbn_parts_max_t, registration_group);				-- add registration group (2)  This applies to each &amp;lt;Rule&amp;gt; in the &amp;lt;Group&amp;gt;&lt;br /&gt;
			table.insert (isbn_parts_min_t, registration_group);				-- add registration group (2)  This applies to each &amp;lt;Rule&amp;gt; in the &amp;lt;Group&amp;gt;&lt;br /&gt;
&lt;br /&gt;
			table.insert (element_lengths_t, #registration_group);				-- add length of isbn registration group (1)  This applies to each &amp;lt;Rule&amp;gt; in the &amp;lt;Group&amp;gt;&lt;br /&gt;
			local range_min, range_max = rule:match (range_pattern);			-- get range limits&lt;br /&gt;
			local registrant_len = rule:match (length_pattern);					-- get the length of the registrant length&lt;br /&gt;
&lt;br /&gt;
			if &amp;#039;0&amp;#039; ~= registrant_len then&lt;br /&gt;
				table.insert (element_lengths_t, tonumber(registrant_len));		-- add length of isbn registrant (2)&lt;br /&gt;
				table.insert (element_lengths_t, 9-#registration_group-registrant_len);	-- calculate and add length available for publication element (3)&lt;br /&gt;
				&lt;br /&gt;
				table.insert (isbn_parts_max_t, range_max:sub (1, registrant_len));	-- add &amp;lt;registrant_len&amp;gt; digits from left side of &amp;lt;range_max&amp;gt; (3)&lt;br /&gt;
				table.insert (isbn_parts_min_t, range_min:sub (1, registrant_len));	-- add &amp;lt;registrant_len&amp;gt; digits from left side of &amp;lt;range_min&amp;gt; (3)&lt;br /&gt;
&lt;br /&gt;
				local fill_length = 0;											-- calculate how many &amp;#039;9&amp;#039;s (or &amp;#039;0&amp;#039;s) are needed to right-fill an isbn&lt;br /&gt;
				for _, v in ipairs (isbn_parts_max_t) do						-- for each part get its length&lt;br /&gt;
					fill_length = fill_length + #(tostring (v));				-- and accumulate&lt;br /&gt;
				end&lt;br /&gt;
				fill_length = 13 - fill_length;									-- and figure how many are needed&lt;br /&gt;
				table.insert (isbn_parts_max_t, string.rep (&amp;#039;9&amp;#039;, fill_length));	-- and right fill to 13 digits&lt;br /&gt;
				table.insert (isbn_parts_min_t, string.rep (&amp;#039;0&amp;#039;, fill_length));	-- and right fill to 13 digits&lt;br /&gt;
&lt;br /&gt;
				local pretty_string = &amp;#039;\t[&amp;#039; .. table.concat (isbn_parts_max_t) .. &amp;#039;] = {&amp;#039; .. table.concat (element_lengths_t, &amp;#039;, &amp;#039;) .. &amp;#039;},&amp;#039;;	-- prettify&lt;br /&gt;
				local pretty_string_range = &amp;#039;\t[&amp;#039; .. table.concat (isbn_parts_max_t) .. &amp;#039;] = &amp;#039; .. table.concat (isbn_parts_min_t) .. &amp;#039;,&amp;#039;;		-- prettify&lt;br /&gt;
				if not agency_used then&lt;br /&gt;
					pretty_string = pretty_string .. string.rep (&amp;#039;\t&amp;#039;, 12) .. &amp;#039;-- &amp;#039; .. agency;	-- add agency to output&lt;br /&gt;
					pretty_string_range = pretty_string_range .. string.rep (&amp;#039;\t&amp;#039;, 11) .. &amp;#039;-- &amp;#039; .. agency;	-- add agency to output&lt;br /&gt;
					agency_used = true;											-- this &amp;#039;agency&amp;#039; added to output; don&amp;#039;t repeat it&lt;br /&gt;
				end&lt;br /&gt;
				table.insert (out_t, pretty_string);							-- add the prettified string to the output sequence&lt;br /&gt;
				table.insert (out_range_t, pretty_string_range);&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if &amp;#039;yes&amp;#039; == frame.args.range then											-- select the output&lt;br /&gt;
		return render_output (frame, &amp;#039;inverse_range_t&amp;#039;, out_range_t, timestamp, timezone, 14);	-- inverse_range_t table&lt;br /&gt;
	else&lt;br /&gt;
		return render_output (frame, &amp;#039;hyphen_pos_t&amp;#039;, out_t, timestamp, timezone, 15);			-- hyphen_pos_t table&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; E X P O R T S &amp;gt;----------------------------------------------------------------&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
return {&lt;br /&gt;
	range_message_xlate = range_message_xlate,&lt;br /&gt;
	}&lt;/div&gt;</summary>
		<author><name>imported&gt;Deadfire</name></author>
	</entry>
</feed>