Module:Lang/data/iana languages/make: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 23:
]=]
 
local function get_element_partsget_lang_script_region_parts (element)
local code = code;
local descriptions = {};
 
for line in mw.ustring.gmatch (element, '([^\n]+)\n') do
if line:mw.ustring.match (line, 'Subtag: [%a%d]+') then
code = line:mw.ustring.match (line, 'Subtag: ([%a%d]+)');
elseif line:mw.ustring.match (line, 'Description: .+') then
table.insert (descriptions, '\"' .. line:mw.ustring.match (line, 'Description: (.+)') .. '\"');
elseif mw.ustring.match (line, '^ .+') then
descriptions[#descriptions] = mw.ustring.gsub (descriptions[#descriptions], '\"$', ''); -- remove trailing quote mark
descriptions[#descriptions] = descriptions[#descriptions] .. ' ' .. mw.ustring.match (line, '^ (.+)') .. '\"';
end
end
return code or 'nil code', table.concat (descriptions, ', ') or 'nil descriptions';
end
 
Line 48 ⟶ 51:
Subtag: aa
Description: Afar
 
 
 
]=]
 
function p.iana_extract_lang (frame)
local page = mw.title.getCurrentTitle(); -- get a page object for this page
local content = page:getContent(); -- get unparsed content
local out_tablelang_table = {}; -- outputlanguages goesgo here
local script_table = {}; -- scripts go here
local region_table = {}; -- regions go here
local file_date; -- first line
local code;
local descriptions;
-- search for nvr links and associated hull numbers
 
_, _, file_date = content:find ('(File%-Date: %d%d%d%d%-%d%d%-%d%d)');
-- for code, lang in mw.ustring.gmatch (content, '%%%%%s*Type:%s*language%s*Subtag:%s*(%l%l%l?)%s*Description:%s*(.-)%s*Added') do
 
for element in mw.ustring.gmatch (content, '%%%%[^%%]+') do
if mw.ustring.find (element, 'Type: language') then
code, descriptions = get_element_partsget_lang_script_region_parts (element);
table.insert (out_table, "[\'" .. code .. "\'] = {" .. descriptions .. "}"); -- make table entries
if code then
table.insert (out_tablelang_table, "[\'" .. code .. "\'] = {" .. descriptions .. "}"); -- make table entries
end
elseif mw.ustring.find (element, 'Type: script') then
code, descriptions = get_lang_script_region_parts (element);
if code then
table.insert (script_table, "[\'" .. code .. "\'] = {" .. descriptions .. "}"); -- make table entries
end
elseif mw.ustring.find (element, 'Type: region') then
code, descriptions = get_lang_script_region_parts (element);
if code then
table.insert (region_table, "[\'" .. code .. "\'] = {" .. descriptions .. "}"); -- make table entries
end
end
end
-- make pretty output
return "<br /><pre>&#9;&#9;-- " .. file_date .. "<br />return {<br />&#9;&#9;" .. table.concat (out_tablelang_table, ',<br />&#9;&#9;') .. "<br />&#9;&#9;},<br /></pre>-- "; ..
file_date .. "<br />return {<br />&#9;" .. table.concat (script_table, ',<br />&#9;') .. "<br />&#9;}<br />-- " ..
file_date .. "<br />return {<br />&#9;" .. table.concat (region_table, ',<br />&#9;') .. "<br />&#9;}<br />" .. "</pre>";
end