模組:Language/name/data/iana data extraction tool
外观
This is a crude tool that reads a local copy of a iso-639-3_Name_Index_YYYYMMDD.tab file from sil.org and extracts the information necessary to create the data table held by Module:Language/data/ISO_639-3
使用
[编辑]要使用這個工具:
- 打開一個新的沙盒分頁並黏貼這個
{{#invoke:}}
到該頁面的第一行;{{#invoke:Language/name/data/ISO 639-3 data extraction tool|ISO_639_3_extract|file-date=YYYYMMDD}}
- YYYYMMDD分別是年、月、日,來自.tab 文件名 (used to place a file-date comment in Module:Language/data/ISO_639-3)
- 下載完整的 Code Tables Set UTF-8 version zip file
- 解壓縮 iso-639-3_Name_Index_YYYYMMDD.tab 並用純文本編輯器打開
- 將其中的資料複製並貼在沙盒分頁的
{{#invoke:}}
下方 - 點擊[顯示預覽]
- 等待
- 得到結果
有一些粗略的錯誤檢查將在輸出中插入錯誤消息。 不保證這種信息會有幫助。 在工具的輸出中搜索“錯誤”一詞。
上述文档嵌入自Module:Language/name/data/iana data extraction tool/doc。 (编辑 | 历史) 编者可以在本模块的沙盒 (创建 | 镜像)和测试样例 (创建)页面进行实验。 本模块的子页面。 |
require('strict');
local p = {};
--[=[------------------------< I S O _ 6 3 9 _ 3 _ E X T R A C T >---------------------------------------------
{{#invoke:Language/name/data/ISO 639-3 data extraction tool|ISO_639_3_extract|file-date=20170217}}
reads a local copy of iso-639-3_Name_Index_YYYYMMDD.tab where (YYYYMMDD is the release date). Download that file
in zip form from http://www-01.sil.org/iso639-3/download.asp (use the UTF-8 zip)
useful lines in the file have the form:
<id>\t<name>\t<inverted name>\n
where:
<id> is the three-character ISO 639-3 language code
<name> is the language 'name'
<inverted name> is the language in 'last-name, first-name(s)' form; this part ignored
like this:
aaq Eastern Abnaki Abnaki, Eastern
when a language code has more than one name, the code is repeated for each additional name:
rar Cook Islands Maori Maori, Cook Islands
rar Rarotongan Rarotongan
]=]
function p.ISO_639_3_extract (frame)
local page = mw.title.getCurrentTitle(); -- get a page object for this page
local content = page:getContent(); -- get unparsed content
local lang_table = {}; -- languages go here
local code;
local names;
local file_date = 'File-Date: ' .. frame.args["file-date"]; -- set the file date line from |file-date=
for code, name in mw.ustring.gmatch (content, '%f[%a](%a%a%a)\t([^\t]+)\t[^\n]+\n') do -- get code and 'forward' name
if code then
if string.find (lang_table[#lang_table] or '', '^%[\"' .. code) then -- if this is an additional name for code ('or' empty string for first time when lang_table[#lang_table] is nil)
lang_table[#lang_table] = mw.ustring.gsub (lang_table[#lang_table], '}$', ''); -- remove trailing brace from previous name
lang_table[#lang_table] = lang_table[#lang_table] .. ', \"' .. name .. '\"}'; -- add this name with new brace
else
table.insert (lang_table, "[\"" .. code .. "\"] = {\"" .. name .. "\"}"); -- make new table entry
end
elseif not code then
table.insert (lang_table, "[\"error\"] = {" .. record .. "}"); -- code should never be nil, but inserting an error entry in the final output can be helpful
end
end
-- make pretty output
return "<br /><pre>-- " .. file_date .. "<br />return {<br />	" .. table.concat (lang_table, ',<br />	') .. "<br />	}<br />" .. "</pre>";
end
return p;