Module:list of languages, csv format
- පහත දැක්වෙන උපදෙස්, Module:list of languages, csv format/documentation හි පිහිටා ඇත. Module:list of languages, csv format/documentation]]. [සංස්කරණය]
- ප්රයෝජනවත් සබැඳි: උප පිටු ලැයිස්තුව • සබැඳි • transclusions • testcases • sandbox
Implements Wiktionary:List of languages, csv format.
local languages = mw.loadData("Module:languages/data/all")
local families = mw.loadData("Module:families/data")
-- based on Module:list_of_languages
local export = {}
local filters = {}
function export.show(frame)
local args = frame.args
local filter = filters[args[1]]
local ids = args["ids"]; if not ids or ids == "" then ids = false else ids = true end
local rows = {}
-- Get a list of all language codes
local codes = {}
for code, _ in pairs(languages) do
table.insert(codes, code)
end
-- Sort the list
table.sort(codes)
local sep = ";"
local minor_sep = ","
local function shallowcopy(array)
local new_array = {}
if type(array) == "string" then array = {array} end
for i, v in ipairs(array) do
new_array[i] = v
end
return new_array
end
-- table.concat can't act on fake table returned by mw.loadData.
-- shallowcopy converts it to a real table.
local concat = table.concat
local function concat_fake(fake_array, sep)
return concat(shallowcopy(fake_array), sep)
end
-- Now go over each code, and create table rows for those that are selected
local column_names = {
"line", "code", "canonical name", "category", "type", "family code",
"family", "sortkey?", "autodetect?", "exceptional?", "script codes",
"other names", "standard characters"
}
for line, code in ipairs(codes) do
local data = languages[code]
local row = {}
local sc = data.scripts or data[4]
-- data[1]: canonical name; data[3]: family code
table.insert(row, line)
table.insert(row, code)
table.insert(row, data[1])
table.insert(row, data[1] .. (data[1]:find("[Ll]anguage$") and "" or " language"))
table.insert(row, data.type or "")
table.insert(row, data[3] or "")
table.insert(row, data[3] and (families[data[3]] and families[data[3]][1] or error(data[3] .. " is not a valid family code (family of " .. code .. ")")))
table.insert(row, data.sort_key and "sortkey" or "")
table.insert(row, data.entry_name and "autodetect" or "")
table.insert(row, code:find("-") and "exceptional" or "")
table.insert(row, sc and concat_fake(sc, minor_sep) or "")
table.insert(row, data.otherNames and concat_fake(data.otherNames, minor_sep) or "")
table.insert(row, data.standardChars and "standard characters" or "")
table.insert(rows, concat(row, sep))
end
return "<pre>\n" .. concat(column_names, sep) .. "\n" .. concat(rows, "\n") .. "</pre>"
end
return export