Mòideal:ISO 639/sandbox
Coltas
(deasbaireachd⧼tpt-languages-separator⧽ ⧼tpt-languages-separator⧽eachdraidh⧼tpt-languages-separator⧽ceanglaichean⧼tpt-languages-separator⧽doc⧼tpt-languages-separator⧽bogsa-gainmhich⧼tpt-languages-separator⧽cùisean deuchainn)
This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
Language templates |
---|
Languages (ISO 639) |
|
Uicleir ceanglaichean-Uici |
|
Eile |
|
Data |
This module could potentially replace the sub template system of Teamplaid:ISO 639 name (Special:PrefixIndex/Template:ISO 639 name) and is used by Teamplaid:ISO 639 code-1, Teamplaid:ISO 639 code-2, Teamplaid:ISO 639 code-3, Teamplaid:ISO 639 code-5.
Eisimpleirean - Examples
name (function) | part1 (function) | part2 (function) | part3 (function) | part5 (function) | part5 (function) hierachy (parameter) | |
---|---|---|---|---|---|---|
English | English | en | eng | eng | ||
en | English | en | eng | eng | ||
EN | English | en | eng | eng | ||
eng | English | en | eng | eng | ||
fr | French | fr | fre | fra | ||
French | French | fr | fre | fra | ||
En | En | enc | ||||
abj | Aka-Bea | abj | ||||
Abellen Ayta | Abellen Ayta | abp | ||||
French, Cajun | Cajun French | frc | ||||
Mande languages | Mande languages | dmn | nic:dmn | |||
apa | Apache languages | apa | apa | nai:xnd:ath:apa | ||
East Germanic languages | East Germanic languages | gme | ine:gem:gme | |||
Germanic languages | Germanic languages | gem | gem | ine:gem:gme |
Subpages
Update
If you feel this Module needs updating you can
- Use Mòideal:ISO 639/data/make to main data table
- Use Mòideal:ISO 639/data/altnames/make to update alternative names
- Manually update Mòideal:ISO 639/data/ISO 639-5 (Only ~100 codes in ISO 639-5, at the Library of Congress at id and en)
}}
local getArgs = require ('Module:Arguments').getArgs;
local p = {}
--[[--------------------------< E R R O R _ M E S S A G E S >-------------------
TODO: change to default hiding of error messages? show with with personal css override:
.show_639_err_msgs {display: inline !important;}
]]
local error_messages = {
-- ['err_msg'] = '<span style="font-size:100%; display:none" class="error show_639_err_msgs">error: $1</span>[[Category:ISO 639 name template errors]]',
['err_msg'] = '<span style="font-size:100%;" class="error show_639_err_msgs"> Error: $1</span>[[Category:ISO 639 name template errors]]',
['err_text'] = {
['required'] = ' ISO 639 code or name is required',
['no_code'] = ' no code in ISO 639-$1 for $2',
['not_found'] = ' $1 not found',
['ietf'] = ' $1 is an IETF tag',
}
}
--[[--------------------------< S U B S T I T U T E >---------------------------
Populates numbered arguments in a message string using an argument table.
]]
local function substitute (msg, args)
return args and mw.message.newRawMessage (msg, args):plain() or msg;
end
--[[--------------------------< E R R O R _ M S G >-----------------------------
create an error message
]]
local function error_msg (msg, arg)
return substitute (error_messages.err_msg, substitute (error_messages.err_text[msg], arg))
end
--[[--------------------------< N A M E >---------------------------------------
template entry point; returns first language name that matches code from template frame or an error message
]]
function p.name (frame)
local args = getArgs(frame);
if not args[1] or args[1] == '{{{1}}}' then
return error_msg ('required');
end
local code = args[1]; -- used in error messaging
local lc_code; -- holds lowercase version of code for indexing into the data tables
local ietf;
code, ietf = code:gsub('(.-)%-.*', '%1'); -- strip ietf subtags; count is non-zero when subtags are stripped
lc_code = code:lower();
if 0 ~= ietf then
ietf = error_msg ('ietf', args[1]);
else
ietf = '';
end
local name_data = mw.loadData ('Module:Language/data/ISO 639 name to code');
local part1_data = mw.loadData ('Module:Language/data/ISO 639-1');
local part2_data = mw.loadData ('Module:Language/data/ISO 639-2');
local part3_data = mw.loadData ('Module:Language/data/ISO 639-3');
local part5_data = mw.loadData ('Module:Language/data/ISO 639-5');
if part1_data[lc_code] then -- If input is part1
return table.concat ({part1_data[lc_code][1],ietf});
elseif part2_data[lc_code] then -- If input is part2
return table.concat ({part2_data[lc_code][1],ietf});
elseif part3_data[lc_code] then -- If input is part3
return table.concat ({part3_data[lc_code][1],ietf});
elseif part5_data[lc_code] then -- If input is part5
return table.concat ({part5_data[lc_code][1],ietf});
elseif name_data[lc_code] then -- If input is name
lc_code = name_data[lc_code]
if part3_data[lc_code[3]][1] then
return table.concat ({part3_data[lc_code[3]][1],ietf});
else
return table.concat ({part5_data[lc_code[4]][1],ietf});
end
end
return error_msg ('not_found', code);
end
--[[--------------------------< R E T U R N C O D E >-----------------------]]--
local function return_code (frame,code_type)
local data = mw.loadData ('Module:Language/data/ISO 639 name to code');
local args = frame["args"]
if not args[1] then
return error_msg ('required'); -- if no input return error
end
args[1] = args[1]:lower()
if not data[args[1]] then -- if input is not in data table
args[1] = p.name(frame) -- set to name using p.name
args[1] = args[1]:lower()
end
if data[args[1]][code_type] ~= "" then
if code_type == 5 then code_type = 4 end
return data[args[1]][code_type]; -- return code
else
return error_msg ('no_code', {code_type,args[1]}); -- or return error
end
end
--[[--------------------------< C O D E 1 >---------------------------------]]--
function p.part1 (frame)
return return_code(frame,1)
end
--[[--------------------------< C O D E 2 >---------------------------------]]--
function p.part2 (frame)
return return_code(frame,2)
end
--[[--------------------------< C O D E 3 >---------------------------------]]--
function p.part3 (frame)
return return_code(frame,3)
end
--[[--------------------------< C O D E 5 >---------------------------------]]--
function p.part5 (frame)
return return_code(frame,5)
end
--[[--------------------------< E X P O R T E D >---------------------------]]--
return p;