Module:Script
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 |
|
Data |
Examples[edit source]
input (parameter) | name (function) | code (function) | number (function) |
---|---|---|---|
[[Khitan]] | Khitan large script | Kitl | 505 |
Kitl | Khitan large script | Kitl | 505 |
Duployan | Duployan shorthand | Dupl | 755 |
Latin | Latin | Latn | 215 |
Klingon | Klingon | Piqd | 293 |
Klingon | Klingon | Piqd | 293 |
External links[edit source]
- Module:Script at Wikipedia, the free Terran-based encyclopedia that anyone can edit.
local p = {}
local getArgs = require('Module:Arguments').getArgs
local data = mw.loadData('Module:Language/data/iso 15924')
function p.code(frame) -- to output part 1 code
frame.args.type = "code"
return p.main(frame)
end
function p.name(frame) -- to output name
frame.args.type = "name"
return p.main(frame)
end
function p.number(frame) -- to output name
frame.args.type = "number"
return p.main(frame)
end
function p.main(frame) -- main function (doesn't need to be called directly)
local args = getArgs(frame)
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"
}
args[1] = mw.ustring.gsub(args[1],"[À-Ý]",accents) -- Deaccent
args[1] = mw.ustring.gsub(args[1],"%[","") -- Delink
args[1] = mw.ustring.gsub(args[1],"%]","") -- Delink
args[1] = mw.ustring.gsub(args[1],"%{","") -- Remove {
args[1] = mw.ustring.gsub(args[1],"%}","") -- Remove }
for code,table in pairs(data) do
for _,value in pairs(table) do
if string.lower(args[1]) == string.lower(value) then
args[1] = code
end
end
if string.lower(args[1]) == string.lower(code)
or string.lower(args[1]) == table.num then
if args.type == "code" then
return code or ""
elseif args.type == "name" then
return table[1] or ""
elseif args.type == "number" then
return table.num or ""
end
end
end
end
return p