Module:ISO 639 name/ISO 639 name to code/make: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 20:
['1']=1, ['2']=2, ['2B']=3, ['3']=4, ['5']=5, -- for the base ISO 639 parts
['O1']=6, ['O2']=7, ['O2B']=8, ['O3']=9, ['O5']=10, -- for the override tables
['D1']=11, ['D2']=12, ['D2B']=13, ['D3']=14, ['D5']=15, -- for the deprecated tables
})[part];
 
Line 30 ⟶ 31:
table.insert (temp[lang], table.concat ({ -- add the code; codes are added in the order that this function is called in iso_639_name_to_code()
'[', -- open the key
part, -- add the language name as index
']=\"', -- close key, add assignment operator and open quote because <code> is a string
code, -- add <code>
Line 93 ⟶ 94:
end
end
end
 
part_data = mw.loadData ('Module:Language/data/ISO 639 deprecated'); -- has deprecated data for all parts
for _, d_part in ipairs ({'1', '2', '2B', '3', '5'}) do -- for each of the deprecated tables
local d_part_data = part_data['deprecated_' .. d_part]; -- point to deprecated data
d_part = 'D' .. d_part; -- prefix d_part
for code, v in pairs (d_part_data) do -- for each code in the data table
for _, lang in ipairs (v) do -- and for each language name associated with that code
lang_add (lang, code, d_part); -- add
end
end
end
 
local function comp (a, b)
return tonumber (a:match ('(%d+)')) < tonumber (b:match ('(%d+)'));
end
 
for lang, codes in pairs (temp) do
table.sort (codes, comp); -- codes are added in the order that lang_add() is called above; sort to make pretty
table.insert (out, table.concat ({'["', lang, '"] = {', table.concat (codes, ', '), '}'})); -- reformat
end
Line 105 ⟶ 121:
'--[[--------------------------< I S O _ 6 3 9 _ N A M E _ T O _ C O D E >--------------------------------------<br /><br />',
'Key:<br />&#9;',
'[1]=ISO 639-1&#9;&#9;[6]=ISO 639-1 override&#9;&#9;[11]=ISO 639-1 deprecated<br />&#9;',
'[2]=ISO 639-2&#9;&#9;[7]=ISO 639-2 override&#9;&#9;[12]=ISO 639-1 deprecated<br />&#9;',
'[3]=ISO 639-2B&#9;&#9;[8]=ISO 639-2B override&#9;&#9;[13]=ISO 639-1 deprecated<br />&#9;',
'[4]=ISO 639-3&#9;&#9;[9]=ISO 639-3 override&#9;&#9;[14]=ISO 639-1 deprecated<br />&#9;',
'[5]=ISO 639-5&#9;&#9;[10]=ISO 639-5 override&#9;&#9;[14]=ISO 639-1 deprecated',
'<br />]]<br /><br />'
})