正在編輯「
模組:Citation/CS1/Language
」
跳至導覽
跳至搜尋
警告:
您尚未登入。 若您進行任何的編輯您的 IP 位址將會被公開。 若您
登入
或
建立帳號
,您的編輯將會以您的使用者名稱標示,並能擁有另外的益處。
防垃圾訊息檢查用。
請勿
填寫此欄位!
--[[--------------------------< F O R W A R D D E C L A R A T I O N S >-------------------------------------- ]] local is_set, in_array, wrap_msg, wrap_style; local add_prop_cat, add_maint_cat; --[[--------------------------< L O C A L _ T A B L E >------------------------------------------------------- ]] local local_table = { ['abe'] = '西阿貝納基語', ['abq'] = '阿巴扎語', ['abq-latn'] = '阿巴扎語(拉丁文字)', ['abs'] = '安汶馬來語', ['ady-cyrl'] = '阿迪格語(西里爾文)', ['aeb-arab'] = '突尼西亞阿拉伯語(阿拉伯文字)', ['aeb-latn'] = '突尼西亞阿拉伯語(拉丁文字)', ['alc'] = '阿拉卡盧夫語', ['ami'] = '阿美語', ['azb'] = '南亞塞拜然語', ['bat-smg'] = '薩莫吉希亞語', ['bbc-latn'] = '多巴巴塔克語(拉丁文字)', ['bcc'] = '南俾路支語', ['bcl'] = '中比科爾語', ['bdr'] = '西海岸巴瑤語', ['be-tarask'] = '百羅斯語(傳統正寫法)', ['be-x-old'] = '百羅斯語(傳統正寫法)', ['bgp'] = '東俾路支語', ['bh'] = '博杰普爾語', ['bxr'] = '俄羅斯布里亞特語', ['cja'] = '西部占語', ['cja-arab'] = '西部占語(阿拉伯文字)', ['cja-cham'] = '西部占語(阿拉伯文字)', ['cja-latn'] = '西部占語(拉丁文字)', ['cjm'] = '東部占語', ['cjm-arab'] = '東部占語(阿拉伯文字)', ['cjm-cham'] = '東部占語(阿拉伯文字)', ['cjm-latn'] = '東部占語(拉丁文字)', ['cjy'] = '晉語', ['cjy-hans'] = '晉語(简體)', ['cjy-hant'] = '晉語(正體)', ['ckt'] = '楚克奇語', ['cnr'] = '蒙特內哥羅語', ['en-in'] = '印度英文', ['en-nz'] = '紐西蘭英文', ['ike-cans'] = '東加拿大語(原住民音節)', ['ike-latn'] = '東加拿大語(拉丁文字)', ['ruq'] = '梅格萊諾-羅馬尼亞語', ['ruq-cyrl'] = '梅格萊諾-羅馬尼亞語(西里爾文字)', ['ruq-grek'] = '梅格萊諾-羅馬尼亞語(希臘文字)', ['ruq-latn'] = '梅格萊諾-羅馬尼亞語(拉丁文字)', ['cdo'] = '閩東語', ['cdo-hani'] = '閩東語(漢字)', ['ja-hani'] = '日文(漢字文字)', ['ja-hira'] = '日文(平假名文字)', ['ja-hrkt'] = '日文(假名文字)', ['ja-kana'] = '日文(片假名文字)', ['ko-kp'] = '北韓韓文', ['kk-cn'] = '中國大陸哈薩克語', ['no'] = '挪威語', ['ojp'] = '古日語', ['ojp-hani'] = '古日語(漢字文字)', ['ojp-hira'] = '古日語(平假名文字)', ['tet'] = '德頓語', ['ug-arab'] = '維吾爾語(阿拉伯文)', ['ug-latn'] = '維吾爾語(拉丁文)', -- ['zh-cn'] = '中國大陸普通話', -- ['zh-hans'] = '簡化字', -- ['zh-hant'] = '正體中文', -- ['zh-hk'] = '香港漢語', ['zh-min-nan'] = '閩南語', -- ['zh-mo'] = '澳門中文', -- ['zh-my'] = '马来西亞中文', -- ['zh-sg'] = '新加坡中文', -- ['zh-tw'] = '臺灣國語', } local function fetchLocalLanguageName (code) return local_table[code]; end --[[--------------------------< F O R M A T _ S C R I P T _ V A L U E >---------------------------------------- |script-title= holds title parameters that are not written in Latin based scripts: Chinese, Japanese, Arabic, Hebrew, etc. These scripts should not be italicized and may be written right-to-left. The value supplied by |script-title= is concatenated onto Title after Title has been wrapped in italic markup. Regardless of language, all values provided by |script-title= are wrapped in <bdi>...</bdi> tags to isolate rtl languages from the English left to right. |script-title= provides a unique feature. The value in |script-title= may be prefixed with a two-character ISO639-1 language code and a colon: |script-title=ja:*** *** (where * represents a Japanese character) Spaces between the two-character code and the colon and the colon and the first script character are allowed: |script-title=ja : *** *** |script-title=ja: *** *** |script-title=ja :*** *** Spaces preceding the prefix are allowed: |script-title = ja:*** *** The prefix is checked for validity. If it is a valid ISO639-1 language code, the lang attribute (lang="ja") is added to the <bdi> tag so that browsers can know the language the tag contains. This may help the browser render the script more correctly. If the prefix is invalid, the lang attribute is not added. At this time there is no error message for this condition. Supports |script-title= and |script-chapter= TODO: error messages when prefix is invalid ISO639-1 code; when script_value has prefix but no script; ]] local function format_script_value (script_value) local lang=''; -- initialize to empty string local name; if script_value:match('^%l%l%s*:') then -- if first 3 non-space characters are script language prefix lang = script_value:match('^(%l%l)%s*:%s*%S.*'); -- get the language prefix or nil if there is no script if not is_set (lang) then return ''; -- script_value was just the prefix so return empty string end -- if we get this far we have prefix and script name = mw.language.fetchLanguageName( lang, mw.getContentLanguage():getCode() ); -- get language name so that we can use it to categorize if is_set (name) then -- is prefix a proper ISO 639-1 language code? script_value = script_value:gsub ('^%l%l%s*:%s*', ''); -- strip prefix from script -- is prefix one of these language codes? if in_array (lang, {'ar', 'bg', 'bs', 'dv', 'el', 'fa', 'he', 'hy', 'ja', 'ka', 'ko', 'ku', 'mk', 'ps', 'ru', 'sd', 'sr', 'th', 'uk', 'ug', 'yi', 'zh'}) then add_prop_cat ('script_with_name', {name, lang}) else add_prop_cat ('script') end lang = ' lang="' .. lang .. '" '; -- convert prefix into a lang attribute else lang = ''; -- invalid so set lang to empty string end end if is_set(script_value) then script_value = '-{R|' .. script_value .. '}-'; end script_value = wrap_style('bdi', {lang, script_value}); -- isolate in case script is rtl return script_value; end --[[--------------------------< S C R I P T _ C O N C A T E N A T E >------------------------------------------ Initially for |title= and |script-title=, this function concatenates those two parameter values after the script value has been wrapped in <bdi> tags. ]] local function script_concatenate (title, script) if is_set(title) then title = '-{R|' .. title .. '}-'; end if is_set (script) then script = format_script_value (script); -- <bdi> tags, lang atribute, categorization, etc; returns empty string on error if is_set (script) then title = title .. ' ' .. script; -- concatenate title and script title end end return title; end --[[--------------------------< G E T _ I S O 6 3 9 _ C O D E >------------------------------------------------ Validates language names provided in |language= parameter if not an ISO639-1 code. Handles the special case that is Norwegian where ISO639-1 code 'no' is mapped to language name 'Norwegian Bokmål' by Extention:CLDR. Returns the language name and associated ISO639-1 code. Because case of the source may be incorrect or different from the case that Wikimedia uses, the name comparisons are done in lower case and when a match is found, the Wikimedia version (assumed to be correct) is returned along with the code. When there is no match, we return the original language name string. mw.language.fetchLanguageNames() will return a list of languages that aren't part of ISO639-1. Names that aren't ISO639-1 but that are included in the list will be found if that name is provided in the |language= parameter. For example, if |language=Samaritan Aramaic, that name will be found with the associated code 'sam', not an ISO639-1 code. When names are found and the associated code is not two characters, this function returns only the Wikimedia language name. Adapted from code taken from Module:Check ISO 639-1. ]] local function get_iso639_code (lang) if 'norwegian' == lang:lower() then -- special case related to Wikimedia remap of code 'no' at Extension:CLDR return '挪威語', 'no'; -- Make sure rendered version is properly capitalized end local languages = mw.language.fetchLanguageNames (mw.getContentLanguage():getCode(), 'all') -- get a list of language names known to Wikimedia -- ('all' is required for North Ndebele, South Ndebele, and Ojibwa) local langlc = mw.ustring.lower (lang); -- lower case version for comparisons for code, name in pairs (languages) do -- scan the list to see if we can find our language if langlc == mw.ustring.lower (name) then if 2 ~= code:len() then -- ISO639-1 codes only return name; -- so return the name but not the code end return name, code; -- found it, return name to ensure proper capitalization and the ISO639-1 code end end return lang; -- not valid language; return language in original case and nil for ISO639-1 code end --[[--------------------------< L A N G U A G E _ P A R A M E T E R >------------------------------------------ Get language name from ISO639-1 code value provided. If a code is valid use the returned name; if not, then use the value that was provided with the language parameter. There is an exception. There are three ISO639-1 codes for Norewegian language variants. There are two official variants: Norwegian Bokmål (code 'nb') and Norwegian Nynorsk (code 'nn'). The third, code 'no', is defined by ISO639-1 as 'Norwegian' though in Norway this is pretty much meaningless. However, it appears that on enwiki, editors are for the most part unaware of the nb and nn variants (compare page counts for these variants at Category:Articles with non-English-language external links. Because Norwegian Bokmål is the most common language variant, Media wiki has been modified to return Norwegian Bokmål for ISO639-1 code 'no'. Here we undo that and return 'Norwegian' when editors use |language=no. We presume that editors don't know about the variants or can't descriminate between them. See Help talk:Citation Style_1#An ISO 639-1 language name test When |language= contains a valid ISO639-1 code, the page is assigned to the category for that code: Category:Norwegian-language sources (no) if the page is a mainspace page and the ISO639-1 code is not 'en'. Similarly, if the parameter is |language=Norwegian, it will be categorized in the same way. This function supports multiple languages in the form |language=nb, French, th where the language names or codes are separated from each other by commas. ]] local function language_parameter (lang) local code; -- the ISO639-1 two character code local name; -- the language name local language_list = {}; -- table of language names to be rendered local names_table = {}; -- table made from the value assigned to |language= if not is_set (lang) then return ''; end names_table = mw.text.split (lang, '%s*,%s*'); -- names should be a comma separated list for _, lang in ipairs (names_table) do -- reuse lang name = fetchLocalLanguageName (lang:lower()); -- local table first if not is_set (name) then if lang:match ('^%a%a%-') or 2 == lang:len() then -- ISO639-1 language code are 2 characters (fetchLanguageName also supports 3 character codes) if lang:match ('^zh-') then name = mw.language.fetchLanguageName (lang:lower(), lang:lower()); else if not is_set (name) then name = mw.language.fetchLanguageName (lang:lower(), mw.getContentLanguage():getCode()); -- get ISO 639-1 language name if Language is a proper code end end end end if is_set (name) then -- if Language specified a valid ISO639-1 code code = lang:lower(); -- save it else name, code = get_iso639_code (lang); -- attempt to get code from name (assign name here so that we are sure of proper capitalization) end if is_set (code) then if 'zh' ~= code and not code:match ('^zh-') then -- Chinese not the language add_prop_cat ('foreign_lang_source', {name, code}) end else add_maint_cat ('unknown_lang'); -- add maint category if not already added end table.insert (language_list, name); name = ''; -- so we can reuse it end code = #language_list -- reuse code as number of languages in the list if 2 >= code then name = table.concat (language_list, '及') -- insert '及' between two language names elseif 2 < code then language_list[code] = '及' .. language_list[code]; -- prepend last name with '及' name = table.concat (language_list, '、'); -- and concatenate with '<comma><space>' separators name = name:gsub ('、及', '及', 1); end return (" " .. wrap_msg ('language', name)); -- otherwise wrap with '(in ...)' end --[[--------------------------< S E T _ S E L E C T E D _ M O D U L E S >-------------------------------------- ]] local function set_selected_modules (utilities_page_ptr, error_page_ptr) is_set = utilities_page_ptr.is_set; -- import functions from selected Module:Citation/CS1/Utilities module in_array = utilities_page_ptr.in_array; wrap_style = utilities_page_ptr.wrap_style; wrap_msg = utilities_page_ptr.wrap_msg; add_prop_cat = error_page_ptr.add_prop_cat; -- import functions from selected Module:Citation/CS1/Error module add_maint_cat = error_page_ptr.add_maint_cat; end --[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------ ]] return { script_concatenate = script_concatenate, language_parameter =language_parameter, set_selected_modules = set_selected_modules }
編輯摘要
(請簡要描述您所作出的修改,或選擇:
新條目
|
修飾語句
|
修正筆誤
|
內容擴充
|
排版
|
來源
|
內部連結
|
分類消歧義
|
維基化
|
維護清理
)
點擊
發布變更
即表示您同意依據
CC BY-SA 4.0
及
GFDL協議
授權您的貢獻,並在CC BY-SA 4.0條款下以超連結或網域(URL)等方式署名。
取消
編輯說明
(在新視窗開啟)
此頁面使用了以下模板:
模組:Citation/CS1/Language/doc
(
編輯
)
導覽選單
個人工具
尚未登入
討論
貢獻
建立帳號
登入
命名空間
模組
討論
English
視圖
閱讀
編輯原始碼
檢視歷史
更多
搜尋
導覽
首頁
近期變更
隨機頁面
維基媒體說明
工具
連結至此的頁面
相關變更
特殊頁面
頁面資訊