Adresa
:
[go:
nahoru
,
domu
]
跳去內容
主目錄
主目錄
移去側欄
收埋
導覽
頭版
社區大堂
最近發生嘅事
最近修改
是但一版
幫手
搵嘢
搵嘢
閱讀設定
慷慨解囊
開戶口
簽到
個人架生
慷慨解囊
開戶口
簽到
未簽到編者用嘅版面
知多啲
貢獻
傾偈
編輯緊
模組:languages/findBestScript
加語言
模組
討論
English
閱
改源碼
睇返紀錄
架撐
架撐
移去側欄
收埋
動作
閱
改源碼
睇返紀錄
基本
有乜連過來
連結頁嘅更改
上載檔案
特別頁
頁面資訊
攞短網址
下載QR code
第啲項目
維基數據項目
閱讀設定
移去側欄
收埋
警告:
閣下重未登入。閣下嘅 IP 地址會喺爾一版嘅修訂歷史裡邊記錄落嚟。
反垃圾檢查。
唔好
填呢個!
return function (export, self, text, scripts, forceDetect, useRequire) -- Ensure that "Hant", "Hans" and "Hani" are moved to the end of the list (in that order, if present), as they are a special-case. local oldScripts, Hant, Hans, Hani, finalCheck = scripts scripts = {} for _, script in ipairs(oldScripts) do if script._code == "Hant" then Hant = script elseif script._code == "Hans" then Hans = script elseif script._code == "Hani" then Hani = script else table.insert(scripts, script) end end if Hant then table.insert(scripts, Hant); finalCheck = true end if Hans then table.insert(scripts, Hans); finalCheck = true end if Hani then table.insert(scripts, Hani) end -- Remove all formatting characters. text = require("Module:utilities").get_plaintext(text) -- Try to match every script against the text, -- and return the one with the most matching characters. local bestcount, bestscript = 0 -- Remove any spacing or punctuation characters, and get resultant length. -- Counting instances of UTF-8 character pattern is faster than mw.ustring.len. local reducedText = mw.ustring.gsub(text, "[%s%p]+", "") local _, length = string.gsub(reducedText, "[\1-\127\194-\244][\128-\191]*", "") -- If the length is 0 then we're probably dealing with a punctuation character, so only remove spacing characters, in case it is script-specific. if length == 0 then reducedText = mw.ustring.gsub(text, "%s+", "") _, length = string.gsub(reducedText, "[\1-\127\194-\244][\128-\191]*", "") if length == 0 then return require("Module:scripts").getByCode("None", nil, nil, useRequire) end end for i, script in ipairs(scripts) do local count = script:countCharacters(reducedText) -- Special case for "Hant", "Hans" and "Hani", which are returned if they match at least one character, under the assumption that (1) traditional and simplified characters will not be mixed if a language uses both scripts, and (2) any terms using Han characters with another script (e.g. Latin) will still need a Han code (not counting those which use Jpan or Kore). This is for efficiency, due to the special checks required for "Hant" and "Hans", and to prevent "Hani" from overriding either, as it will always match with at least as many characters, while characters used in both will only match with "Hani". if count >= length or ((script._code == "Hant" or script._code == "Hans" or script._code == "Hani") and count > 0) then return script elseif count > bestcount then bestcount = count bestscript = script end end -- Secondary check for languages that have "Hant" or "Hans" but not "Hani", but which still have multiple scripts (e.g. Macau Pidgin Portuguese): characters which are not exclusively traditional or simplified will not be found by the main check, so a separate "Hani" check is necessary to see if Han characters are present at all. If successful, return "Hant" or "Hans" as applicable. if finalCheck and not Hani then for _, script in ipairs(scripts) do if (script._code == "Hant" or script._code == "Hans") and (require("Module:scripts").getByCode("Hani", nil, nil, useRequire):countCharacters(reducedText) > 0) then return script end end end if bestscript then return bestscript end -- No matching script was found, so return "None". return require("Module:scripts").getByCode("None", nil, nil, useRequire) end
摘要:
當保存嗰陣,你同意
使用條款
,亦將你嘅貢獻喺
共享創意 署名-相同方式共享 4.0
同埋
GFDL自由文檔協議
發表。 你同意只係用超連結或者網址做署名已經足夠。
取消
編輯幫手
(響新視窗度打開)
Preview page with this template
維基數據 entities used in this page
模組:scripts/findBestScript
:Sitelink、Description: en
呢版用嘅模:
模組:languages/findBestScript/doc
(
編輯
)