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

Content deleted Content added
No edit summary
No edit summary
Line 5:
--[=[------------------------< G E T _ L A N G _ S C R I P T _ R E G I O N _ P A R T S >-----------------------
 
We get an elementrecord that looks more-or-less like this:
%%\n
Type: language\n
Line 22:
than one Description line and Description lines can wrap to the next line. When they do, the first two
characters of the continuation line are spaces.
 
Comments: lines can also be continued so once in a Comments line (which is otherwise ignored) all further
continuations in the record are also ignored. This is a crude mechanism to prevent comment continuations
from being concatenated onto the end of descriptions and relies on Description line occuring in the record
before the Comments line.
 
Records with Deprecated dates or Preferred-Value codes are ignored as are private use codes.
 
]=]
 
local function get_lang_script_region_parts (elementrecord)
local code;
local descriptions = {};
local in_comments = false;
 
for line inif mw.ustring.gmatchmatch (elementrecord, '([^\n]+)\nDeprecated') do then -- getor amw.ustring.find \n(record, terminate'Preferred%-Value') lineor of textmw.ustring.find (withoutrecord, the'Private \nuse') then
return 'skip';
end
 
for line in mw.ustring.gmatch (record, '([^\n]+)\n') do -- get a \n terminate line of text (without the \n)
if mw.ustring.match (line, 'Subtag: [%a%d]+') then -- if this line is the subtag line
code = mw.ustring.match (line, 'Subtag: ([%a%d]+)'); -- extract and save to subtag's code
Line 72 ⟶ 83:
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 elementrecord in mw.ustring.gmatch (content, '%%%%([^%%]+)') do -- get a %% delimited 'elementrecord' from the file; leave off the delimiters
if mw.ustring.find (elementrecord, 'Type: language') then -- if a language elementrecord
code, descriptions = get_lang_script_region_parts (elementrecord); -- get the code and description(s)
if code and ('skip' ~= code) then
table.insert (lang_table, "[\"" .. code .. "\"] = {" .. descriptions .. "}"); -- make table entries
elseif not code then
else
table.insert (lang_table, "[\"error\"] = {" .. record .. "}"); -- code should never be nil, but inserting an error entry in the final output can be helpful
end
 
elseif mw.ustring.find (elementrecord, 'Type: script') then -- if a script elementrecord
code, descriptions = get_lang_script_region_parts (elementrecord); -- get the code and description(s)
if code and ('skip' ~= code) then
table.insert (script_table, "[\"" .. code .. "\"] = {" .. descriptions .. "}"); -- make table entries
elseif not code then
else
table.insert (lang_table, "[\"error\"] = {" .. record .. "}"); -- code should never be nil, but ...
end
 
elseif mw.ustring.find (elementrecord, 'Type: region') then -- if a region elementrecord
code, descriptions = get_lang_script_region_parts (elementrecord); -- get the code and description(s)
if code and ('skip' ~= code) then
table.insert (region_table, "[\"" .. code .. "\"] = {" .. descriptions .. "}"); -- make table entries
elseif not code then
else
table.insert (lang_table, "[\"error\"] = {" .. record .. "}"); -- code should never be nil, but ...
end
end