Module:Lang:修订间差异
删除的内容 添加的内容
enwiki>Theknightwho Comments re class="error". No changes to code. 标签:已被回退 |
CaelLab-import(留言 | 贡献) huifu bei enwiki daoru dingti de banben (shangyiban CaelLab-import) 标签:手工回退 |
||
第1行:
--[=[
Lua support for the {{lang}}, {{langx}}, {{lang-??}}, and {{transliteration}} templates and replacement of various supporting templates.
-- 中文維基百科:加入了error_msgs,用於將所有報錯情形修改爲試圖顯示正常內容並附加預設不可見的錯誤報告。
]=]
第40行 ⟶ 第42行:
local maint_cats = {}; -- maintenance categories go here
local maint_msgs = {}; -- and their messages go here
local error_msgs = {}
第47行 ⟶ 第51行:
local function make_error_span (template, msg)
return table.concat ({'<span class="error" style="font-size: 1em;">', cfg.misc_text_t.error, ':', template, msg, '</span>'})
end
local function make_lang_error_span (msg)
return table.concat ({'<span class="lang-comment lang-comment-error" style="font-style: normal; display: none; margin-left: 0.3em; color: #33aa33;">', msg, '</span>'})
end
第85行 ⟶ 第91行:
category = cfg.make_error_msg_t.lang_err_cat;
end
local category_link = ((0 == namespace or 10 == namespace) and not args_t.nocat) and substitute ('[[Category:$1]]', {category}) or '';
text = text or cfg.make_error_msg_t.undefined
if text == '' then
text = cfg.make_error_msg_t.empty
end
-- {{$3}} = {{$3}}
-- 防止特定情況下作爲模板展開
table.insert(error_msgs, substitute ('-{[$1]}-<span class="error" style="font-size: 1em; margin-left: 0.3em;">$2:{{$3}}:$4([[:Category:$5|$6]])</span>$7',
{
text,
cfg.misc_text_t.error,
template,
第99行 ⟶ 第111行:
category_link
})
)
return error_msgs[#error_msgs]
end
--[[--------------------------< P A R A M E T E R _ V A L I D A T E >------------------------------------------
第108行 ⟶ 第122行:
local function parameter_validate (args_t, template)
local err_msg = cfg.parameter_validate_t.invalid_param;
local ret = {}
if cfg.templates_t.lang == template then -- for {{lang}}
第113行 ⟶ 第129行:
if not cfg.known_params_t.params_lang_t[param] and -- unique {{lang}} parameters
not cfg.known_params_t.common_params_all_t[param] then -- common to all
end
end
第121行 ⟶ 第137行:
not cfg.known_params_t.params_x_t[param] and -- common to {{langx}} and {{lang-xx}}
not cfg.known_params_t.common_params_all_t[param] then -- common to all
end
end
第129行 ⟶ 第145行:
not cfg.known_params_t.params_x_t[param] and -- common to {{langx}} and {{lang-xx}}
not cfg.known_params_t.common_params_all_t[param] then -- common to all
end
end
end
if ret[1] then
return table.concat(ret, '、')
end
end
第177行 ⟶ 第197行:
seg[3] = source:match ('.+(%f[\']\'\'+)$') or ''; -- get trailing markup, if any; ignore single quote
if '' ~= seg[1] and '' ~= seg[3] then -- extract the 'text'
seg[2] = source:match ('^\'\'+%f[^\'](.+)%f[\']\'\'+$') -- from between leading and trailing markup
elseif '' ~= seg[1] then
第205行 ⟶ 第225行:
When both |italic= and |italics= are set, returns nil and a 'conflicting' error message.
The return value nil causes the calling lang, lang_xx, or
defined default ('inherit' for {{lang}}, 'inherit' or 'italic' for {{lang-??}} depending on
the individual template's requirements, 'italic' for {{transliteration}}) or to the value appropriate to |script=, if set ({{lang}}
第222行 ⟶ 第242行:
local function validate_italic (args)
local properties = {[cfg.keywords_t.affirmative] = 'italic', [cfg.keywords_t.negative] = 'normal', [cfg.keywords_t.unset] = 'inherit', [cfg.keywords_t.invert] = 'invert', [cfg.keywords_t.default] = nil};
local
for _,
count = count + 1
end
end
return properties[args.italic or args.italics or args.i], count > 1 and cfg.validate_italic_t.multi_italic or nil
end
第268行 ⟶ 第277行:
return;
end
if false == yesno (args.cat) or true == yesno (args.nocat) then
args.nocat = true; -- set to true when args.nocat is affirmative; nil else (as if the parameter were not set in the template)
第304行 ⟶ 第313行:
variant: lower case
private: lower case prefixed with -x-
]]
第313行 ⟶ 第322行:
return table.concat ({code:lower(), 'x', private:lower()}, '-'); -- if private, all other tags ignored
end
table.insert (out, code:lower());
if is_set (script) then
第323行 ⟶ 第332行:
table.insert (out, region:upper());
end
if is_set (variant) then
table.insert (out, variant:lower());
end
return table.concat (out, '-');
end
第346行 ⟶ 第355行:
lang-region lang-region-variant
lang-script-region lang-script-region-variant
lang-x-private
each of lang, script, region, variant, and private, when used, must be valid.
第361行 ⟶ 第370行:
See http://www.rfc-editor.org/rfc/bcp/bcp47.txt section 2.1.
]]
第370行 ⟶ 第379行:
return nil, nil, nil, nil, nil, cfg.get_ietf_parts_t.missing_lang_tag;
end
local override = { -- 簡寫轉換爲正確的語言標籤
['pinyin'] = 'zh-Latn-pinyin', -- 漢語拼音
['zhuyin'] = 'zh-Bopo', -- 注音符號
}
source = override[source] or source
local pattern = { -- table of tables holding acceptable IETF tag patterns and short names of the IETF part captured by the pattern
第376行 ⟶ 第392行:
{'^(%a%a%a?)%-(%a%a%a%a)%-(%a%a)%-(%w%w%w%w%w%w?%w?%w?)$', 's', 'r', 'v'}, -- 3 - ll-Ssss-RR-variant (where variant is 5-8 alnum characters)
{'^(%a%a%a?)%-(%a%a%a%a)%-(%d%d%d)%-(%w%w%w%w%w%w?%w?%w?)$', 's', 'r', 'v'}, -- 4 - ll-Ssss-DDD-variant (where region is 3 digits; variant is 5-8 alnum characters)
{'^(%a%a%a?)%-(%a%a%a%a)%-(%d%d%d%d)$', 's', 'v'}, -- 5 - ll-Ssss-variant (where variant is 4 digits)
{'^(%a%a%a?)%-(%a%a%a%a)%-(%w%w%w%w%w%w?%w?%w?)$', 's', 'v'}, -- 6 - ll-Ssss-variant (where variant is 5-8 alnum characters)
{'^(%a%a%a?)%-(%a%a)%-(%d%d%d%d)$', 'r', 'v'}, -- 7 - ll-RR-variant (where variant is 4 digits)
{'^(%a%a%a?)%-(%d%d%d)%-(%d%d%d%d)$', 'r', 'v'}, -- 8 - ll-DDD-variant (where region is 3 digits; variant is 4 digits)
{'^(%a%a%a?)%-(%a%a)%-(%w%w%w%w%w%w?%w?%w?)$', 'r', 'v'}, -- 9 - ll-RR-variant (where variant is 5-8 alnum characters)
{'^(%a%a%a?)%-(%d%d%d)%-(%w%w%w%w%w%w?%w?%w?)$', 'r', 'v'}, -- 10 - ll-DDD-variant (where region is 3 digits; variant is 5-8 alnum characters)
{'^(%a%a%a?)%-(%d%d%d%d)$', 'v'}, -- 11 - ll-variant (where variant is 4 digits)
{'^(%a%a%a?)%-(%w%w%w%w%w%w?%w?%w?)$', 'v'}, -- 12 - ll-variant (where variant is 5-8 alnum characters)
{'^(%a%a%a?)%-(%a%a%a%a)%-(%a%a)$', 's', 'r'}, -- 13 - ll-Ssss-RR
{'^(%a%a%a?)%-(%a%a%a%a)%-(%d%d%d)$', 's', 'r'}, -- 14 - ll-Ssss-DDD (region is 3 digits)
{'^(%a%a%a?)%-(%a%a%a%a)$', 's'}, -- 15 - ll-Ssss
{'^(%a%a%a?)%-(%a%a)$', 'r'}, -- 16 - ll-RR
{'^(%a%a%a?)%-(%d%d%d)$', 'r'}, -- 17 - ll-DDD (region is 3 digits)
{'^(%a%a%a?)$'}, -- 18 - ll
{'^(%a%a%a?)%-x%-(%w%w?%w?%w?%w?%w?%w?%w?)$', 'p'}, -- 19 - ll-x-pppppppp (private is 1-8 alnum characters)
}
第405行 ⟶ 第422行:
for i, v in ipairs (pattern) do -- spin through the pattern table looking for a match
local c1, c2, c3, c4; -- captures in the 'pattern' from the pattern table go here
c1, c2, c3, c4 = source:match (pattern[i][1]); -- one or more captures set if source matches pattern[i])
if c1 then -- c1 always set on match
第427行 ⟶ 第444行:
code = code:lower(); -- ensure that we use and return lower case version of this
if not (override_table[code] or lang_table[code] or synonym_table[code] or lang_dep_table[code]) then
return nil, nil, nil, nil, nil, substitute (cfg.get_ietf_parts_t.unrecog_code, {code});
end
第444行 ⟶ 第461行:
else
script = args_script or ''; -- use args.script if provided
end
if is_set (script) then
第464行 ⟶ 第481行:
else
region = args_region or ''; -- use args.region if provided
end
if is_set (region) then
第472行 ⟶ 第489行:
end
end
if is_set (variant) then
if is_set (args_variant) then
第479行 ⟶ 第496行:
else
variant = args_variant or ''; -- use args.variant if provided
end
if is_set (variant) then
第492行 ⟶ 第509行:
elseif is_set (region) then -- if region set, there are some prefixes that require lang code and region (en-CA-newfound)
if not in_array (code, variant_table[variant]['prefixes']) then -- first see if lang code is all that's required (en-oxendict though en-GB-oxendict is preferred)
if not in_array (table.concat ({code, '-', region}), variant_table[variant]['prefixes']) then
return code, script, region, nil, nil, substitute (cfg.get_ietf_parts_t.unrecog_var_code_reg, {variant, code, region});
end
第505行 ⟶ 第522行:
if is_set (private) then
private = private:lower(); -- ensure that we use and return lower case version of this
if not override_table[table.concat ({code, '-x-', private})] then -- make sure private tag is valid; note that index
return code, script, region, nil, nil, substitute (cfg.get_ietf_parts_t.unrecog_pri, {private});
end
第576行 ⟶ 第593行:
local function title_wrapper_make (title_text, content_text, tag)
local wrapper_t = {};
table.insert (wrapper_t, table.concat ({'<', tag})); -- open opening wrapper tag
table.insert (wrapper_t, ' title=\"'); -- begin title attribute
第653行 ⟶ 第670行:
local title_text;
if 'zxx' == code then -- special case for this tag 'no linguistic content'
title_text = substitute ('$1
elseif mw.ustring.find (language, '
title_text = substitute ('$1
else
title_text = substitute ('$1
end
第663行 ⟶ 第680行:
else
return table.concat (html_t);
end
end
-- 中文版添加,实现#ifexist
local function page_exists (title)
local noError, titleObject = pcall (mw.title.new, title)
if not noError then
return false
else
if titleObject then
return titleObject.exists
else
return false
end
end
end
第674行 ⟶ 第705行:
For English:
[[Category:Articles containing explicitly cited English-language text]]
For ISO 639-2 collective languages (and for 639-1 bh):
[[Category:Articles with text in <language> languages]]
注意:此处有修改
对于中文(zh、zh-*):
如果[[Module:Lang/data]]没有额外定义变体名称(即取得的语言名称是「中文」),则返回以下分类:
[[Category:含有明确引用中文的条目]]
反之,则返回以下分类:
[[Category:含有<变体>的条目]]
对于非中文内容:
如果存在对应语言的分类,则返回以下分类:
[[Category:含有<语言>的条目]]
反之,则返回以下分类:
[[Category:含有非中文内容的条目]]
]=]
第685行 ⟶ 第734行:
end
-- 中文版无
-- if mw.ustring.find (language_name, '语系', 1, true) then
-- return substitute ('[[$1 $2]]', {cfg.make_category_t.collective_cat, language_name});
-- end
if this_wiki_lang_tag == code and language_name == '中文' then -- 名稱必須是「中文」
return substitute ('[[$1$2$3$4]]', { -- unique category name for the local language
cfg.make_category_t.cat_prefix,
cfg.make_category_t.explicit_cat,
第696行 ⟶ 第746行:
cfg.make_category_t.cat_postfix,
});
elseif (page_exists (substitute ('$1$2$3', {
cfg.make_category_t.cat_prefix,
language_name,
cfg.make_category_t.cat_postfix,
}))) then
return substitute ('[[$1$2$3]]', { -- category for individual languages
cfg.make_category_t.cat_prefix,
language_name,
cfg.make_category_t.cat_postfix,
});
else
return substitute ('[[$1$2$3]]', { -- 非中文内容
cfg.make_category_t.cat_prefix,
cfg.make_category_t.cat_nonezh,
cfg.make_category_t.cat_postfix,
});
第717行 ⟶ 第777行:
to be |translit-script= (in this function, tscript).
This function is used by both lang_xx() and
lang_xx() always provides code, language_name, and translit; may provide tscript; never provides style
For {{transliteration}}, style only applies when a language code is provided.
第725行 ⟶ 第785行:
]]
local function make_translit (code, language_name, translit, std, tscript, style
local title_t = lang_data.translit_title_table; -- table of transliteration standards and the language codes and scripts that apply to those standards
local title_text = ''; -- tool tip text for title= attribute
std = std and std:lower(); -- lower case for table indexing
if not is_set (std) and not is_set (tscript) then -- when neither standard nor script specified
title_text = language_name; -- write a generic tool tip
title_text = substitute ('$1$2', {title_text, cfg.lang_xx_t.romanization}); -- 中文版添加
-- 中文版不需要
-- if not mw.ustring.find (language_name, 'languages', 1, true) then -- collective language names (plural 'languages' is part of the name)
-- title_text = substitute ('$1
-- end
-- title_text = substitute ('$1 $2', {title_text, mw.ustring.lower (cfg.engvar_t[engvar]['romanisz_lc'])}); -- finish the tool tip; use romanization when neither script nor standard supplied
elseif is_set (std) and is_set (tscript) then -- when both are specified
第742行 ⟶ 第804行:
if title_t[std][tscript] then -- and if script for that standard is legitimate
if script_table[tscript] then
title_text = substitute ('$1$
title_text,
title_t[std][tscript:lower()],
script_table[tscript],
cfg.make_translit_t.transliteration,
});
第756行 ⟶ 第817行:
end
else
return translit
end
elseif is_set (std) then -- translit-script not set, use language code
if not title_t[std] then
return translit
end
if title_t[std][code] then -- if language code is in the table (transl may not provide a language code)
title_text = substitute ('$1$2($3)$4', { -- add the appropriate text to the tool tip
title_text,
title_t[std][code:lower()],
language_name,
cfg.make_translit_t.transliteration,
});
第786行 ⟶ 第843行:
else
if is_set (tscript) then
title_text = substitute ('$1$2-$3
title_text,
language_name,
第792行 ⟶ 第849行:
cfg.make_translit_t.transliteration,
});
-- 中文版不需要
-- elseif is_set (code) then
-- if not mw.ustring.find (language_name, 'languages', 1, true) then -- collective language names (plural 'languages' is part of the name)
-- title_text = substitute ('$1-$2', { -- skip this text (individual and macro languages only)
-- title_text,
-- cfg.misc_text_t.language,
-- });
-- end
-- title_text = substitute ('$1 $2', { -- finish the tool tip
-- title_text,
-- cfg.make_translit_t.transliteration,
-- });
else
title_text = substitute ('$1
title_text,
cfg.make_translit_t.transliteration,
第816行 ⟶ 第873行:
if is_set (code) then -- when a language code is provided (always with {{lang-??}} templates, not always with {{transliteration}})
code = code:match ('^(%a%a%a?)'); -- strip all subtags leaving only the language subtag
if not style then --
tag = '<
else
tag = '<span style="font-style: %s" lang="%s-Latn">%s</span>' -- non-standard style, construct a span tag for it
第826行 ⟶ 第883行:
tag = '<span>%s</span>' -- when no language code: no lang= attribute, not italic ({{transliteration}} only)
end
tag = string.format(tag, translit) -- add the translit text
if '' == title_text then -- when there is no need for a tool-tip
return tag; -- done
else
-- 中文版不需要
-- title_text = cfg.engvar_sel_t.gb == engvar and title_text:gsub ('([Rr]omani)z', '%1s') or title_text; -- gb eng when engvar specifies gb eng; us eng else
return title_wrapper_make (title_text, tag, 'span'); -- wrap with a tool-tip span and done
end
第849行 ⟶ 第907行:
local function validate_text (template, args)
if not is_set (args.text) then
args.text = ''
return
end
if args.text:find ("%f[\']\'\'\'\'%f[^\']") or args.text:find ("\'\'\'\'\'[\']+") then -- because we're looking, look for 4 appostrophes or 6+ appostrophes
return
end
local
-- 中文版修改:|italic=no 和未指定 |italic= 時不檢查斜體標記
if style and (cfg.keywords_t.unset ~= style) and (cfg.keywords_t.negative ~= style) and (cfg.keywords_t.invert ~= style) then
if args.text:find ("%f[\']\'\'%f[^\']") or args.text:find ("%f[\']\'\'\'\'\'%f[^\']") then -- italic but not bold, or bold italic
return
end
end
第874行 ⟶ 第937行:
local function render_maint (nocat)
local maint = {};
if 0 < #maint_msgs then -- when there are maintenance messages
table.insert (maint, table.concat ({'<span class="lang-comment" style="font-style: normal; display: none; color: #33aa33; margin-left: 0.3em;">'})); -- opening <span> tag
for _, msg in ipairs (maint_msgs) do
table.insert (maint, table.concat ({msg, '
end
table.insert (maint, '</span>'); -- close the span
end
if (0 < #maint_cats) and (0 == namespace) and not nocat then -- when there are maintenance categories; article namespace only
for _, cat in ipairs (maint_cats) do
第888行 ⟶ 第951行:
end
end
return table.concat (maint);
end
第907行 ⟶ 第970行:
if false == proto_param then -- when forced by |proto=no
return text:gsub ('^%**', ''); -- return text without splat prefix regardless of language name or existing splat prefix in text
elseif (language_name:find ('^
return text:gsub ('^%**', '*'); -- prefix proto-language text with a splat; also removes duplicate prefixing splats
end
return text:gsub ('^%*+', '*'); -- return text unmolested except multiple splats reduced to one splat
end
第934行 ⟶ 第997行:
If text contains:
\n\n text has implied <p>..</p> tags - trim leading and trailing whitespace and return
If text begins with list markup:
\n* unordered
第942行 ⟶ 第1,005行:
trim all leading whitespace except \n and trim all trailing whitespace
If text contains <poem>...</poem> stripmarker, return text unmodified and choose <div>..</div> tags because
the stripmarker is replaced with text wrapped in <div>..</div> tags.
第952行 ⟶ 第1,015行:
local function html_tag_select (text)
local tag;
if has_poem_tag (text) then -- contains poem stripmarker (we can't know the content of that)
tag = 'div'; -- poem replacement is in div tags so lang must use div tags
第967行 ⟶ 第1,030行:
tag = 'span'; -- so span is fine
end
return text, tag;
end
第1,003行 ⟶ 第1,066行:
local function language_name_get (ietf, code, cat)
ietf = ietf:lower(); -- ietf:lower() because format_ietf_tag() returns mixed case
local name; -- remains nil if not found
if override_table[ietf] then -- look for whole IETF tag in override table
name = override_table[ietf];
第1,078行 ⟶ 第1,141行:
while 1 do
idx_mid = math.ceil ((idx_bot + idx_top) / 2); -- get the mid-point in the <ranges_t> sequence
if (target >= ranges_t[idx_mid][1]) and (target <= ranges_t[idx_mid][2]) then
return true; -- we found the range that holds the <target> character; return true
elseif (target > ranges_t[idx_mid][2]) then -- is <target> > indexed range high value?
idx_bot = idx_mid; -- adjust <idx_bot> up
第1,091行 ⟶ 第1,154行:
break; -- here when we just evaluated the last range and <target> not found
end
if not flag and (idx_bot == idx_top) then -- set true just before we evaluate the last (highest) range in <ranges_t>
flag = true;
第1,136行 ⟶ 第1,199行:
end
--[[--------------------------< 处 理 中 文 文 本 转 换 >--------------------------------------------------------------
该函数用于判断输入的语言代码是否属于中文(包括汉语方言),并决定是否需要禁用繁简转换。
功能:
- 如果语言代码指定为无变体的中文代码 `zh-` 和其他以汉字作为书写系统的汉语方言文字(如粤语、吴语、赣语、文言文等),则返回原文本,不做任何修改。
- 如果语言代码不属于中文或为中文变体(以 `zh-` 开头),则在文本外添加 `-{}-`,以阻止繁简转换。
参数:
- `code` (string): 语言代码(如 `"zh"`、`"gan"`、`"yue"`、`"en"`)。
- `text` (string): 需要处理的文本。
返回值:
- (string) 处理后的文本。
]]
local function chinese_conversion(code, text)
-- 定义属于中文及相关方言的语言代码
local chinese_codes = { zh = true, gan = true, wuu = true, yue = true, lzh = true, hsn = true }
if chinese_codes[code] then
return text
else
return '-{' .. text .. '}-'
end
end
--[[--------------------------< _ L A N G >--------------------------------------------------------------------
第1,160行 ⟶ 第1,252行:
maint_cats = {}; -- initialize because when this module required into another module, these only declared once so only initialzed once
maint_msgs = {};
error_msgs = {}
validate_cat_args (args); -- determine if categorization should be suppressed
if args[1] and args.code then
end
args.code = args[1] or args.code; -- prefer args.code
if args[2] and args.text then
end
args.text = args[2] or args.text; -- prefer args.text
validate_text (template, args)
args.text, tag = html_tag_select (args.text); -- inspects text; returns appropriate HTML tag with text trimmed accordingly
第1,197行 ⟶ 第1,281行:
if msg then
msg = nil
code = code or ''
end
local is_latn_text, pos, char;
is_latn_text, args.text, pos, char= is_latin (args.text, code); -- make a boolean
msg = text_script_match_test (subtags.script, is_latn_text, pos, char)
if msg then -- if an error detected then there is an error message
msg = nil
end
args.italic, msg = validate_italic (args);
if msg then
make_error_msg (msg, args, template)
msg = nil
end
if nil == args.italic then -- nil when |italic= absent or not set or |italic=default; args.italic controls
if ('latn' == subtags.script) or -- script is latn
(this_wiki_lang_tag ~= code and not is_set (subtags.script) and not has_poem_tag (args.text) and is_latn_text) then -- text not this wiki's language, no script specified and not in poem markup but is wholly latn script (auto-italics)
-- 中文版默认不应用斜体
args.italic = 'unset'; -- DEFAULT for {{lang}} templates is upright; but if latn script set for font-style:italic
else
args.
end
end
if is_set (subtags.script) then -- if script set, override rtl setting
if in_array (subtags.script, lang_data.rtl_scripts) then
第1,226行 ⟶ 第1,320行:
args.code = format_ietf_tag (code, subtags.script, subtags.region, subtags.variant, subtags.private); -- format to recommended subtag styles
language_name = language_name_get (args.code, code, true) or '';
if cfg.keywords_t.invert == args.
args.text = invert_italics (args.text)
end
args.text = chinese_conversion (args.code, args.text) -- 中文版特化部分
args.text = proto_prefix (args.text, language_name, args.proto); -- prefix proto-language text with a splat
table.insert (out, make_text_html (args.code, args.text, tag, args.rtl, args.
table.insert (out, make_category (code, language_name, args.nocat));
table.insert (out, render_maint (args.nocat)); -- maintenance messages and categories
if not args.noerror and error_msgs[1] then
table.insert(out, make_lang_error_span(table.concat(error_msgs)))
end
return table.concat (out); -- put it all together and done
第1,271行 ⟶ 第1,371行:
local msg = parameter_validate (args_t, cfg.templates_t.lang); -- verify that all supplied parameters are supported by {{lang-??}}
if
msg = ''
else
msg = msg and make_lang_error_span(make_error_msg(msg, args_t, cfg.templates_t.lang)) or ''
end
return _lang (args_t)
end
第1,288行 ⟶ 第1,390行:
local function translation_make (args_t)
local translation_t = {'
if 'none' ~= args_t.label then -- if we want a label
table.insert (translation_t, '<small>'); -- open the <small> HTML tag
if cfg.keywords_t.negative == args_t.link then
table.insert (translation_t,
else
table.insert (translation_t, make_wikilink (cfg.translation_make_t.lit_xlation
end
table.insert (translation_t, "
end
table.insert (translation_t, table.concat ({
return table.concat (translation_t); -- make a big string and done
end
第1,340行 ⟶ 第1,436行:
|label = 'none' to suppress all labeling (language name, 'translit.', 'lit.')
any other text replaces language-name label - automatic wikilinking disabled
for those {{lang-??}} templates that support transliteration (those templates where |text= is not entirely latn script):
|translit = text that is a transliteration of text
第1,354行 ⟶ 第1,450行:
]]
local function _lang_xx (args, base_template) -- base_template will be either of '
local out = {};
local language_name; -- used to make display text, article links
第1,369行 ⟶ 第1,465行:
maint_cats = {}; -- initialize because when this module required into another module, these only declared once so only initialzed once
maint_msgs = {};
error_msgs = {}
local text_idx = (cfg.templates_t.langx == base_template) and 2 or 1; -- for {{langx}} 'text' positional parameter is '2'
local translit_idx = (cfg.templates_t.langx == base_template) and 3 or 2;
第1,375行 ⟶ 第1,473行:
if args[text_idx] and args.text then
end
args.text = args[text_idx] or args.text; -- prefer positional 'text' parameter
validate_text (template, args)
args.text, tag = html_tag_select (args.text); -- inspects text; returns appropriate HTML tag with text trimmed accordingly
if args[translit_idx] and args.translit then
end
args.translit = args[translit_idx] or args.translit; -- prefer positional 'translit' parameter
if args[xlate_idx] and (args.translation or args.lit) then
elseif args.translation and args.lit then
end
args.translation = args[xlate_idx] or args.translation or args.lit; -- prefer positional 'translation' parameter
if args.links and args.link then
end
args.link = args.link or args.links; -- prefer args.link
validate_cat_args (args); -- determine if categorization should be suppressed
第1,422行 ⟶ 第1,505行:
if msg then -- if an error detected then there is an error message
msg = nil
code = code or ''
end
if args.translit then
local latn, pos, char;
latn, args.translit, pos, char = is_latin (args.translit, (('' ~= subtags.private) and (code .. '-x-' .. subtags.private)) or code);
if not latn then
end
end
第1,438行 ⟶ 第1,523行:
msg = text_script_match_test (subtags.script, is_latn_text, pos, char)
if msg then -- if an error detected then there is an error message
msg = nil
end
args.italic, msg = validate_italic (args);
if msg then
make_error_msg (msg, args, template)
msg = nil
end
if cfg.templates_t.langx == base_template then -- auto-italics for {{langx}} templates; adapted from {{lang}} (no support for poem tag)
if nil == args.italic then -- nil when |italic= absent or not set or |italic=default; args.italic controls
args.italic = 'inherit'; -- italic not set; script not latn; inherit current style
end
else -- {{lang-xx}} does not do auto italics; retained for those wikis that don't support {{langx}}
if nil == args.
args.italic = initial_style_state; -- here when |italic= and |script= not set; set for font-style:<initial_style_state>
end
end
if is_set (subtags.script) then -- if script set override rtl setting
if in_array (subtags.script, lang_data.rtl_scripts) then
第1,479行 ⟶ 第1,558行:
args.code = format_ietf_tag (code, subtags.script, subtags.region, subtags.variant, subtags.private); -- format to recommended subtag styles
language_name = language_name_get (args.code, code, true) or '';
category_name = language_name; -- category names retain IANA parenthetical diambiguators (if any)
第1,486行 ⟶ 第1,565行:
if args.label then
if 'none' ~= args.label then
table.insert (out, table.concat ({args.label, '
end
else
第1,492行 ⟶ 第1,571行:
table.insert (out, language_name); -- language name without wikilink
else
-- 中文版不需要
-- if mw.ustring.find (language_name, 'languages', 1, true) then
-- table.insert (out, make_wikilink (language_name)); -- collective language name uses simple wikilink
--
--
if lang_data.article_name[code] then -- is language tag in article override
table.insert (out, make_wikilink (lang_data.article_name[code], language_name)); -- language name with wikilink from override data
else
table.insert (out, make_wikilink (
end
end
table.insert (out, '
end
第1,508行 ⟶ 第1,588行:
args.text = invert_italics (args.text)
end
args.text = chinese_conversion (args.code, args.text) -- 中文版特化部分
args.text = proto_prefix (args.text, language_name, args.proto); -- prefix proto-language text with a splat
table.insert (out, make_text_html (args.code, args.text, tag, args.rtl, args.
if is_set (args.translit) and not is_latn_text then -- transliteration; not supported when args.text is wholly latn text (this is an imperfect test)
table.insert (out, '
if 'none' ~= args.label then
table.insert (out, '<small>');
第1,523行 ⟶ 第1,605行:
end
local translit_title_obj = mw.title.makeTitle (0, substitute ('$2$1
if translit_title_obj.exists and (cfg.keywords_t.negative ~= args.link) then
table.insert (out, make_wikilink (substitute ('
substitute ('$1', {cfg.
else
table.insert (out, substitute ('$
end
table.insert (out, '
end
translit = make_translit (args.code, language_name, args.translit, args['translit-std'], args['translit-script'], nil
if is_set (translit) then
table.insert (out, translit);
else
end
elseif is_set (args.translit) and is_latn_text then -- when creating a transliteration of Latn script <text>
end
第1,549行 ⟶ 第1,631行:
table.insert (out, translation_make (args));
end
table.insert (out, make_category (code, category_name, args.nocat));
table.insert (out, render_maint(args.nocat)); -- maintenance messages and categories
if not args.noerror and error_msgs[1] then
table.insert(out, make_lang_error_span(table.concat(error_msgs)))
end
return table.concat (out); -- put it all together and done
第1,597行 ⟶ 第1,683行:
local args = lang_xx_args_get (frame, cfg.templates_t.langxx);
args.fn = nil; -- unset because not supported but this function might have been called by {{lang|fn=lang_xx_italic|...}}
local msg = parameter_validate (args, cfg.templates_t.langxx); -- verify that all supplied parameters are supported by {{lang-??}}
if args.noerror then
msg = ''
else
msg = msg and make_lang_error_span(make_error_msg(msg, args, cfg.templates_t.langxx)) or ''
end
initial_style_state = args.italic_important and 'italic' or 'inherit'; -- 中文維基百科:忽略斜體(除非指定italic_important)
return _lang_xx (args, cfg.templates_t.langxx) .. msg .. '[[Category:
end
第1,615行 ⟶ 第1,704行:
local function _lang_xx_italic (args)
initial_style_state = args.italic_important and 'italic' or 'inherit'; -- 中文維基百科:忽略斜體(除非指定italic_important)
return _lang_xx (args, cfg.templates_t.langxx);
end
第1,631行 ⟶ 第1,720行:
local msg = parameter_validate (args, cfg.templates_t.langxx); -- verify that all supplied parameters are supported by {{lang-??}}
if args.noerror then
msg = ''
else
msg = msg and make_lang_error_span(make_error_msg(msg, args, cfg.templates_t.langxx)) or ''
end
initial_style_state = 'inherit';
return _lang_xx (args, cfg.templates_t.langxx) .. msg .. '[[Category:
end
第1,659行 ⟶ 第1,751行:
local function _langx (args_t)
local langx_data = mw.loadData ('Module:Lang/langx'); -- get necessary data
local rtl_t = langx_data.rtl_t; -- get list of language tags for languages that are rendered right-to-left
local link_t = langx_data.link_t; -- get list of language tags for {{lang-??}} templates that set |link=<something>
local size_t = langx_data.size_t; -- get list of language tags for {{lang-??}} templates that set |size=<something>
error_msgs = {}
local msg = parameter_validate (args_t, cfg.templates_t.langx);
if msg then
msg = nil
end
args_t.code = args_t[1] or args_t.code; -- get the language tag; must be {{{1}}} or |code=
if not args_t.code then
end
args_t.rtl = args_t.rtl or (rtl_t[args_t.code] and cfg.keywords_t.affirmative); -- prefer |rtl= in template call, use rtl_t else
args_t.link = args_t.link or link_t[args_t.code]; -- prefer |link= in template call, use link_t felse
args_t.size = args_t.size or size_t[args_t.code]; -- prefer |size= in template call, use size_t else
args_t[1] = nil; -- unset to mimic {{lang-??}} templates which set |code=xx
if not args_t.noerror and error_msgs[1] then
msg = make_lang_error_span(table.concat(error_msgs))
end
local lang_subtag = args_t.code; -- use only the base language subtag for unsupported tag test; some args_t.code are modified by |script= etc
return _lang_xx (args_t, cfg.templates_t.langx)
end
第1,692行 ⟶ 第1,791行:
but {{langx}} has four:
| 1 | 2 | 3 | 4
{{lang-xx |<text> |<
{{langx |<tag> |<text> |<
The calls to lang_xx_args_get() and _lang_xx() use '
positional parameters.
第1,708行 ⟶ 第1,807行:
local function langx (frame)
local args_t = lang_xx_args_get (frame, cfg.templates_t.langx); -- get the arguments; '
return _langx (args_t);
end
第1,776行 ⟶ 第1,875行:
local msg; -- gets an error message if IETF language tag is malformed or invalid
local language_name = '';
code, subtags.script, subtags.region, subtags.variant, subtags.private, msg = get_ietf_parts (raw_code);
if msg then
local template = (args['template'] and table.concat ({'{{', args['template'], '}}
return make_error_span (template, msg);
end
第1,791行 ⟶ 第1,890行:
if link then -- when |link=yes, wikilink the language name
if mw.ustring.find (language_name, '
language_name = make_wikilink (language_name, label); -- collective language name uses simple wikilink
elseif lang_data.article_name[raw_code:lower()] then -- is IETF tag in article name override?
第1,798行 ⟶ 第1,897行:
language_name = make_wikilink (lang_data.article_name[code], label or language_name); -- language name with wikilink from override data
else
language_name = make_wikilink (
end
end
第1,812行 ⟶ 第1,911行:
]]
local function name_from_tag (frame) -- entry point from an {{#invoke:
return _name_from_tag (getArgs(frame)) -- pass-on the args table, nothing else; getArgs() so we also get parent frame
end
第1,831行 ⟶ 第1,930行:
if args[1] and '' ~= args[1] then
local data = mw.loadData ('Module:Lang/tag from name' .. sandbox);
local lang = args[1]:lower(); -- allow any-case for the language name (speeling must till be correct)
local tag = data.rev_override_table[lang] or data.rev_lang_table[lang] or data.rev_lang_dep_table[lang]; -- get the code; look first in the override then in the standard
第1,846行 ⟶ 第1,945行:
local template = '';
if args.template and '' ~= args.template then
template = table.concat ({'{{', args['template'], '}}
end
return make_error_span (template, msg);
第1,859行 ⟶ 第1,958行:
]]
local function tag_from_name (frame) -- entry point from an {{#invoke:
local result, _ = _tag_from_name (getArgs(frame)) -- pass-on the args table, nothing else; getArgs() so we also get parent frame; supress second return used by is_lang_name()
return result;
end
第1,873行 ⟶ 第1,972行:
local function is_lang_name (frame)
local _, result = _tag_from_name (getArgs(frame)) -- pass-on the args table, nothing else; getArgs() so we also get parent frame; supress second return used by tag_from_name()
return result and true or nil;
end
--[[--------------------------< _
Module entry point from another module.
第1,883行 ⟶ 第1,982行:
]]
local function
local title_table = lang_data.translit_title_table; -- table of transliteration standards and the language codes and scripts that apply to those standards
local language_name; -- language name that matches language code; used for tool tip
第1,893行 ⟶ 第1,992行:
maint_cats = {}; -- initialize because when this module required into another module, these only declared once so only initialzed once
maint_msgs = {};
error_msgs = {}
if is_set (args[3]) then -- [3] set when {{transliteration|code|standard|text}}
args.text = args[3]; -- get the transliterated text
第1,899行 ⟶ 第2,000行:
if not title_table[args.translit_std] then
args.translit_std = nil
end
else
第1,907行 ⟶ 第2,009行:
if args[1] and (args[1]:match ('^%a%a%a?%a?$') or -- args[2] missing; is args[1] a language or script tag or is it the transliterated text?
args[1]:match ('^%a%a%a?%-x%-')) then -- or is args[1] a private-use tag
args.text = ''
else
make_error_msg (cfg.transl_t.missing_lang_scr, args, template)
args.text = ''
end
end
第1,919行 ⟶ 第2,022行:
args.code = args[1]:lower(); -- use the language/script code; only (2, 3, or 4 alpha characters) or private-use; lower case because table indexes are lower case
else
args.code = ''
end
else
args.code = ''
end
第1,928行 ⟶ 第2,033行:
is_latn_text, args.text, pos, char= is_latin (args.text, args.code); -- is latn text? strip accept-as-written markup
if not is_latn_text then -- when text is not latn
end
args.italic, msg = validate_italic (args);
if msg then
msg = nil
end
if 'italic' == args.italic then -- 'italic' when |italic=yes; because that is same as absent or not set and |italic=default
args.italic = nil; -- set to nil;
end
if override_table[args.code] then -- is code a language code defined in the override table?
第1,955行 ⟶ 第2,059行:
args.code = ''; -- unset because not a language code
else
language_name = args.code
end
-- here only when all parameters passed to make_translit() are valid
if not args.noerror and error_msgs[1] then
msg = make_lang_error_span(table.concat(error_msgs))
end
return make_translit (args.code, language_name, args.text, args.translit_std, script, args.italic) .. (msg or '')
end
--[[--------------------------<
Module entry point from an {{#invoke:}}.
第1,968行 ⟶ 第2,078行:
]]
local function
return
end
第1,991行 ⟶ 第2,101行:
local msg; -- gets an error message if IETF language tag is malformed or invalid
local category_name = '';
code, subtags.script, subtags.region, subtags.variant, subtags.private, msg = get_ietf_parts (raw_code);
if msg then
local template = (args_t.template and table.concat ({'{{', args_t.template, '}}
return make_error_span (template, msg);
end
第2,016行 ⟶ 第2,126行:
]]
local function category_from_tag (frame) -- entry point from an {{#invoke:
return _category_from_tag (getArgs (frame)); -- pass-on the args table, nothing else; getArgs() so we also get parent frame
end
第2,035行 ⟶ 第2,145行:
tag_from_name = tag_from_name, -- returns IETF tag associated with language name
name_from_tag = name_from_tag, -- used for template documentation; possible use in ISO 639 name from code templates
_category_from_tag = _category_from_tag, -- API entry points when this module is require()d into other modules
_lang = _lang,
第2,044行 ⟶ 第2,154行:
_is_ietf_tag = _is_ietf_tag,
get_ietf_parts = get_ietf_parts,
_tag_from_name = _tag_from_name,
_name_from_tag = _name_from_tag,
_translation_make = translation_make,
};
| |||