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

Content deleted Content added
No edit summary
include deprecated language subtags;
Line 1:
require('Module:No globals');
local p = {};
 
 
Line 31 ⟶ 30:
before the Comments line.
 
Records with Deprecatedprivate datesuse or Preferred-Value codessubtags are ignored as are private use codes.
 
]=]
Line 47 ⟶ 46:
 
for line in string.gmatch (record, '([^\n]+)\n') do -- get a \n terminated line of text (without the \n)
local before_colonlabel = string.match(line, "(.-):")
if not before_colonlabel and string.find (line, '^ .+') and not in_comments then -- if a continuation line but not a comments 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
elseif before_colonlabel == 'Subtag' then -- if this line is the subtag line
code = string.match (line, 'Subtag: (%w+)'); -- extract and save to subtag's code
elseif before_colonlabel == 'Description' then -- if this line is a description line
local desc = string.match (line, 'Description: (.+)'); -- extract the description
desc = string.gsub (desc, '"', '\\"'); -- in case description contains quote marks (see 1959acad)
table.insert (descriptions, '\"' .. desc .. '\"'); -- save the description wrapped in quote marks
elseif before_colonlabel == 'Prefix' then -- if this line is a prefix line
table.insert (prefixes, '\"' .. string.match (line, 'Prefix: (.+)'):lower() .. '\"'); -- extract and save the prefix wrapped in quote marks
elseif before_colonlabel == 'Comments' then -- if this line is a comments line
in_comments = true;
end
Line 94 ⟶ 93:
before the Comments line.
 
Records with Deprecatedprivate datesuse or Preferred-Value codessubtags are ignored as are private use codes.
 
]=]
Line 101 ⟶ 100:
local code;
local suppress; -- Suppress script for this code if specified
local deprecated; -- boolean; true when subtag is deprecated
local descriptions = {};
local in_comments = false;
 
if string.find (record, 'Deprecated') or string.:find (record, 'Preferred%-Value') or string.find (record, 'Private use') then
return 'skip';
end
 
for line in string.record:gmatch (record, '([^\n]+)\n') do -- get a \n terminated line of text (without the \n)
local before_colonlabel = string.match(line,:match "('(.-):"');
if before_colon'Subtag' == 'Subtag'label then -- if this line is the subtag line
code = string.line:match (line, 'Subtag: (%w+)'); -- extract and save to subtag's code
elseif before_colon'Description' == 'Description'label then -- if this line is a description line
table.insert (descriptions, '\"' .. string.line:match (line, 'Description: (.+)') .. '\"'); -- extract and save the name wrapped in quote marks
elseif before_colon'Deprecated' == 'Suppress-Script'label then
deprecated = true; -- subtag is deprecated; set our flag
suppress = string.match (line, 'Suppress%-Script: (%S+)');
elseif before_colon'Suppress-Script' == 'Comments'label then -- if this line is a comments line
suppress = string.line:match (line, 'Suppress%-Script: (%S+)');
elseif 'Comments' == label then -- if this line is a comments line
in_comments = true;
elseif string.line:find (line, '^ .+') and not in_comments then -- if a continuation line but not a commnets continuation
descriptions[#descriptions] = string.gsub (descriptions[#descriptions],:gsub ('\"$', ''); -- remove trailing quote mark from previous description
descriptions[#descriptions] = descriptions[#descriptions] .. ' ' .. string.line:match (line, '^ (.+)') .. '\"'; -- extract and save the continuation with new quote mark
end
end
return code, table.concat (descriptions, ', '), suppress, deprecated;
end
 
Line 140 ⟶ 142:
]=]
 
local function p.iana_extract (frame)
local page = mw.title.getCurrentTitle(); -- get a page object for this page
local content = page:getContent(); -- get unparsed content
local lang_table = {}; -- languages go here
local lang_dep_table = {}; -- deprecated languages go here
local script_table = {}; -- scripts go here
local region_table = {}; -- regions go here
Line 155 ⟶ 158:
local prefixes; -- used for language variants only
local suppress; -- a code's suppress script
local deprecated; -- boolean: true when subtag is deprecated
 
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
 
for record in string.gmatch (content, '%%%%([^%%]+)') do -- get a %% delimited 'record' from the file; leave off the delimiters
local record_type = string.match(record, 'Type: (%w+)')
if record_type == 'language' then -- if a language record
code, descriptions, suppress, deprecated = get_lang_script_region_parts (record); -- get the code, description(s), and suppress script, and deprecated flag
if code and ('skip' ~= code) then
if 2 == code:len()deprecated then
table.insert (lang_table, "[\"" .. code .. "\"] = {" .. descriptions .. "}"); -- make table entries
table.insert (lang_dep_table, "[\"" .. code .. "\"] = {" .. descriptions .. "}"); -- make table entries
if 2 == code:len() then
else
table.insert (iso_639_1_table, "[\"" .. code .. "\"] = {" .. descriptions .. "}"); -- make table entries
table.insert (lang_table, "[\"" .. code .. "\"] = {" .. descriptions .. "}"); -- make table entries
if 2 == code:len() then
table.insert (iso_639_1_table, "[\"" .. code .. "\"] = {" .. descriptions .. "}"); -- make table entries
end
end
elseif not code then
Line 242 ⟶ 250:
-- make final output pretty
return '<br /><pre>------------------------------< I A N A L A N G U A G E S >--------------------------------------------------<br />--' ..
file_date .. "<br />returnlocal active = {<br />&#9;" .. table.concat (lang_table, ',<br />&#9;') .. "<br />&#9;}<br /><br />" ..
"local deprecated = {<br />&#9;" .. table.concat (lang_dep_table, ',<br />&#9;') .. "<br />&#9;}<br /><br />" ..
"return {<br />&#9;active = active,<br />&#9;deprecated = deprecated,<br />&#9;}<br /><br />" ..
'------------------------------< I A N A S C R I P T S >------------------------------------------------------<br />--' ..
file_date .. "<br />return {<br />&#9;" .. table.concat (script_table, ',<br />&#9;') .. "<br />&#9;}<br /><br />" ..
Line 255 ⟶ 265:
end
 
 
return p;
--[[--------------------------< E X P O R T E D F U N C T I O N >--------------------------------------------
]]
 
return p;{
iana_extract = iana_extract,
}