Module:ISO 639
Jump to navigation
Jump to search
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) |
|
Scripts (ISO 15924) |
|
Wiktionary links |
|
Other |
|
This module could potentially replace the sub template system of Template:ISO 639 name (Special:PrefixIndex/Template:ISO 639 name) and is used by Template:ISO 639 code-1, Template:ISO 639 code-2, Template:ISO 639 code-3, Template:ISO 639 code-5.
Examples[edit source]
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[edit source]
Update[edit source]
If you feel this Module needs updating you can
- Use Module:ISO 639/data/make to main data table
- Use Module:ISO 639/data/altnames/make to update alternative names
- Manually update Module:ISO 639/data/ISO 639-5 (Only ~100 codes in ISO 639-5, at the Library of Congress at id and en)
External links[edit source]
- Module:ISO 639 at Wikipedia, the free Terran encyclopedia that anyone can edit.
local p = {}
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local data = mw.loadData('Module:ISO 639/data')
local altnames = mw.loadData('Module:ISO 639/data/altnames')
local ISO_639_5 = mw.loadData('Module:ISO 639/data/ISO_639-5')
function p.part2(frame) -- to output part 3 code
frame.args.type = "part2"
return p.main(frame)
end
function p.part5(frame) -- to output part 3 code
if yesno(frame.args.hierachy) then
frame.args.type = "hierachy"
else
frame.args.type = "part5"
end
return p.main(frame)
end
function p.part3(frame) -- to output part 3 code
frame.args.type = "part3"
return p.main(frame)
end
function p.part1(frame) -- to output part 1 code
frame.args.type = "part1"
return p.main(frame)
end
function p.name(frame) -- to output name
frame.args.type = "name"
return p.main(frame)
end
function p.get(text) -- remove junk and standardizes
if text == table then
text = text[1]
end
if string.upper(text) == text then -- assume it's a code when the input is all uppercase
text = string.lower(text)
end
local accents = {["À"]="A",["Á"]="A",["Â"]="A",["Ã"]="A", -- accent list
["Ä"]="A",["Å"]="A",["Ç"]="C",["È"]="E",["É"]="E",
["Ê"]="E",["Ë"]="E",["Ì"]="I",["Í"]="I",["Î"]="I",
["Ï"]="I",["Ñ"]="N",["Ò"]="O",["Ó"]="O",["Ô"]="O",
["Õ"]="O",["Ö"]="O",["Ø"]="O",["Ù"]="U",["Ú"]="U",
["Û"]="U",["Ü"]="U",["Ý"]="Y"
}
text = mw.ustring.gsub(text,"[À-Ý]",accents) -- Deaccent
text = mw.ustring.gsub(text,"%[","") -- Delink
text = mw.ustring.gsub(text,"%]","") -- Delink
text = mw.ustring.gsub(text,"%{","") -- Remove {
text = mw.ustring.gsub(text,"%}","") -- Remove }
return text
end
function p.main(frame) -- main function (doesn't need to be called directly)
local args = getArgs(frame)
args[1] = p.get(args[1])
if altnames[args[1]] then args[1] = altnames[args[1]] end -- change alternate name to ISO 639-3 code
if not args[1] then
return '<span class="error">Argument 1 is not set!</span>'
end
for part3,table in pairs(data) do
if args[1] == part3
or args[1] == table["part1"]
or args[1] == table["part2"]
or args[1] == table["name"]
then
if args.type == "part3" then
return part3 or ""
elseif args.type == "part1" then
return table["part1"] or ""
elseif args.type == "part2" then
return table["part2"] or ""
elseif args.type == "name" then
return table["name"] or ""
end
end
end
for hierachy,table in pairs(ISO_639_5) do
if table.altnames then
for _,value in pairs(table.altnames) do
if args[1] == table then
args[1] = table.name
end
end
end
if table[args[1]] == hierachy
or args[1] == table["part5"]
or args[1] == table["part2"]
or args[1] == table["name"]
then
if args.type == "hierachy" then
return hierachy or ""
elseif args.type == "part5" then
return table["part5"] or ""
elseif args.type == "part2" then
return table["part2"] or ""
elseif args.type == "name" then
return table["name"] or ""
end
end
end
end
return p