Content deleted Content added
codes in prefixes to lower case; |
+suppressed script extraction; |
||
Line 97:
local function get_lang_script_region_parts (record)
local code;
local suppress; -- Suppress script for this code if specified
local descriptions = {};
local in_comments = false;
Line 104 ⟶ 105:
end
for line in string.gmatch (record, '([^\n]+)\n') do -- get a \n terminated line of text (without the \n)
if string.find (line, 'Subtag: [%a%d]+') then -- if this line is the subtag line
code = string.match (line, 'Subtag: ([%a%d]+)'); -- extract and save to subtag's code
elseif string.find (line, 'Description: .+') then -- if this line is a description line
table.insert (descriptions, '\"' .. string.match (line, 'Description: (.+)') .. '\"'); -- extract and save the name wrapped in quote marks
elseif string.find (line, '
suppress = string.match (line, 'Suppress%-Script: (%S+)');
elseif string.find (line, 'Comments: .+') then -- if this line is a comments line
in_comments = true;
elseif string.find (line, '^ .+') and not in_comments then -- if a continuation line but not a commnets continuation
descriptions[#descriptions] = string.gsub (descriptions[#descriptions], '\"$', ''); -- remove trailing quote mark from previous description
descriptions[#descriptions] = descriptions[#descriptions] .. ' ' .. string.match (line, '^ (.+)') .. '\"'; -- extract and save the continuation with new quote mark
Line 117 ⟶ 120:
end
return code, table.concat (descriptions, ', '), suppress;
end
Line 140 ⟶ 143:
local region_table = {}; -- regions go here
local variant_table = {}; -- variants go here
local suppress_table = {}; -- here we collect suppressed scripts and associated language codes
local file_date; -- first line
Line 145 ⟶ 149:
local descriptions;
local prefixes; -- used for language variants only
local suppress; -- a code's suppress script
file_date = content:match ('(File%-Date: %d%d%d%d%-%d%d%-%d%d)'); -- get the file date line from this version of the source file
Line 150 ⟶ 155:
for record in string.gmatch (content, '%%%%([^%%]+)') do -- get a %% delimited 'record' from the file; leave off the delimiters
if string.find (record, 'Type: language') then -- if a language record
code, descriptions, suppress = get_lang_script_region_parts (record); -- get the code
if code and ('skip' ~= code) then
Line 156 ⟶ 161:
elseif not code then
table.insert (lang_table, "[\"error\"] = {" .. record .. "}"); -- code should never be nil, but inserting an error entry in the final output can be helpful
end
-- here we collect suppress stript tags and their associated language codes;
-- prettigying the data in this table must wait until all language codes have been read
if suppress then -- if this code has a suppressed script
local suppressed_code = table.concat ({'\"', code, '\"'}); -- wrap the code in quotes
if suppress_table[suppress] then -- if there is an entry for this script
table.insert (suppress_table[suppress], suppressed_code); -- insert the new code
else
suppress_table[suppress] = {}; -- add new script and empty table
table.insert (suppress_table[suppress], suppressed_code); -- insert the new code
end
end
Line 196 ⟶ 213:
end
end
-- now prettify the supressed script table
local pretty_suppressed = {};
for script, code_tbl in pairs (suppress_table) do
table.insert (pretty_suppressed,
table.concat ({'[\"', script, '\"] = {', table.concat (code_tbl, ', '), '}'})
);
end
table.sort (pretty_suppressed);
-- make pretty output
return "<br /><pre>-- " .. file_date .. "<br />return {<br />	" .. table.concat (lang_table, ',<br />	') .. "<br />	}<br />-- " ..
file_date .. "<br />return {<br />	" .. table.concat (script_table, ',<br />	') .. "<br />	}<br />-- " ..
file_date .. "<br />return {<br />	" .. table.concat (region_table, ',<br />	') .. "<br />	}<br />-- " ..
file_date .. "<br />return {<br />	" .. table.concat (variant_table, ',<br />	') .. "<br />	}<br />-- " ..
file_date .. "<br />return {<br />	" .. table.concat (pretty_suppressed, ',<br />	') .. "<br />	}<br />" .. "</pre>";
end
|