Module:ISO 639
外观
| 此模組仰賴以下其他模組: |
將 ISO 639 系列1,2,3 的語言代碼轉換為繁體中文的語言名稱。
zh→ 中文zh-hant→ 繁體中文zh-hans→ 簡體中文lzh→ 文言文nan→ 閩南語yue→ 粵語wuu→ 吳語
en→ 英文el→ 希臘文fr→ 法文grc→ 古希臘文ja→ 日文ko→ 韓文vi→ 越南文
用法
[编辑]local language_name = require('Module:ISO 639')
language_name(code)
殼模板
[编辑]可使用殼模板 {{ISO 639 name}}。錯誤資訊的分類在Category:ISO 639 name template errors。
用法:
local ISO_639_name = require('Module:ISO 639')._ISO_639_name
ISO_639_name({code})
ISO_639_name({code = code})
{{#invoke:ISO 639|ISO_639_name|code}}
require('strict')
local p = {}
local getArgs = require('Module:Arguments').getArgs
local warn = require('Module:Warning')
local languageNameOverrides = mw.loadData('Module:ISO 639/overrides')
--[=[
Get the language name, in English, for a given ISO 639 (-1, -2 or -3) code
Returns nil if the language is not in the lookup tables.
]=]
function p.language_name(code, failValue)
-- Only continue if we get passed a non-empty string for the code param
if code == nil or code == '' then
warn('No ISO code provided to [[Module:ISO 639]]')
return failValue
elseif type(code) ~= 'string' then
warn('ISO code \"' .. tostring(code) .. '\" is not a string')
return failValue
end
-- If we have a local override, apply it
local language = languageNameOverrides[code]
-- Otherwise, ask MediaWiki for the language name in English for this code
if language == nil or language == '' then
language = mw.language.fetchLanguageName(code, 'zh-hant')
end
-- If we got no name from MediaWiki and have no override for this code,
-- load the big honkin' local lookup table and check there.
if language == nil or language == '' then
local localLanguageNames = mw.loadData('Module:ISO 639/local')
language = localLanguageNames[code]
end
-- If we found a non-empty lang name we return it.
if language ~= nil and language ~= '' then
return language
end
-- otherwise we return the failure value
warn('ISO code \"' .. code .. '\" not recognized by [[Module:ISO 639]]')
return failValue
end
--[=[
Implements [[Template:ISO 639 name]]
]=]
function p.ISO_639_name(frame)
local args = getArgs(frame)
return p.language_name(args[1] or args.code, '[[Category:' .. 'ISO 639 name template errors' .. ']]')
end
return p