Mô đun:Language
![](http://upload.wikimedia.org/wikipedia/commons/thumb/4/43/Test_Template_Info-Icon_-_Version_%282%29.svg/50px-Test_Template_Info-Icon_-_Version_%282%29.svg.png)
require('strict')local m_data = mw.loadData("Module:Language/data")local langData = m_data.languages or m_datalocal p = {}local function ifNotEmpty(value)if value == "" thenreturn nilelsereturn valueendendlocal function makeLinkedName(languageCode)local data = langData[languageCode]local article = data["article"]local name = data["Wikipedia_name"] or data["name"]return "[[" .. article .. "|" .. name .. "]]: "endlocal function makeEntryName(word, languageCode)local data = langData[languageCode]local ugsub = mw.ustring.gsubword = tostring(word)if word == nil thenerror("The function makeEntryName requires a string argument")elseif word == "" thenreturn ""else-- Remove bold and italics, so that words that contain bolding or emphasis can be linked without piping.word = word:gsub("\'\'\'", "")word = word:gsub("\'\'", "")if data == nil thenreturn wordelselocal replacements = data and data["replacements"]if replacements == nil thenreturn wordelse-- Decompose so that the diacritics of characters such-- as á can be removed in one go.-- No need to compose at the end, because the MediaWiki software-- will handle that.if replacements.decompose thenword = mw.ustring.toNFD(word)for i, from in ipairs(replacements.from) doword = ugsub(word,from,replacements.to and replacements.to[i] or "")endelsefor regex, replacement in pairs(replacements) doword = ugsub(word, regex, replacement)endendreturn wordendendendendp.makeEntryName = makeEntryNamelocal function fixScriptCode(firstLetter, threeLetters)return string.upper(firstLetter) .. string.lower(threeLetters)endlocal function getCodes(codes, text)local languageCode, scriptCode, invalidCodelocal errorTextif codes == nil or codes == "" thenerrorText = 'no language or script code provided'elseif codes:find("^%a%a%a?$") or codes:find("^%a%a%a?%-%a%a%a%a$") then-- A three- or two-letter lowercase sequence at beginning of first parameterlanguageCode =codes:find("^%a%a%a?") and (codes:match("^(%l%l%l?)")or codes:match("^(%a%a%a?)"):gsub("(%a%a%a?)", string.lower, 1))-- One uppercase and three lowercase letters at the end of the first parameterscriptCode =codes:find("%a%a%a%a$") and (codes:match("(%u%l%l%l)$")or gsub(codes:match("(%a%a%a%a)$"),"(%a)(%a%a%a)",fixScriptCode,1))elseif codes:find("^%a%a%a?%-%a%a%a?$")or codes:find("^%a%a%a%-%a%a%a%-%a%a%a$") thenlanguageCode = codes-- Private-use subtag: x followed by one or more sequences of 1-8 lowercase-- letters separated by hyphens. This only allows for one sequence, as it is-- needed for proto-languages such as ine-x-proto (Proto-Indo-European).elseif codes:find("^%a%a%a?%-x%-%a%a?%a?%a?%a?%a?%a?%a?$") thenlanguageCode, scriptCode =codes:match("^(%a%a%a%-x%-%a%a?%a?%a?%a?%a?%a?%a?)%-?(.*)$")if not languageCode thenerrorText = '<code>'..codes..'</code> is not a valid language or script code.'elseif scriptCode ~= "" and not scriptCode:find("%a%a%a%a") thenerrorText = '<code>'..scriptCode..'</code> is not a valid script code.'elsescriptCode = scriptCode:gsub("(%a)(%a%a%a)",fixScriptCode,1)endelseif codes:find("^%a%a%a?") thenlanguageCode, invalidCode = codes:match("^(%a%a%a?)%-?(.*)")languageCode = string.lower(languageCode)errorText = '<code>'..invalidCode..'</code> is not a valid script code.'elseif codes:find("%-?%a%a%a%a$") theninvalidCode, scriptCode = codes:match("(.*)%-?(%a%a%a%a)$")scriptCode = gsub(scriptCode,"(%a)(%a%a%a)",fixScriptCode)errorText = '<code>'..invalidCode..'</code> is not a valid language code.'elseerrorText = '<code>'..codes..'</code> is not a valid language or script code.'endif not scriptCode or scriptCode == "" thenscriptCode = require("Module:Unicode data").is_Latin(text) and "Latn" or "unknown"endif errorText thenerrorText = ' <span style="font-size: smaller">[' .. errorText .. ']</span>'elseerrorText = ""endlanguageCode = m_data.redirects[languageCode] or languageCodereturn languageCode, scriptCode, errorTextendlocal function tag(text, languageCode, script, italics)local data = langData[languageCode]-- Use Wikipedia code if it has been given: for instance,-- Proto-Indo-European has the Wiktionary code "ine-pro" but the Wikipedia-- code "ine-x-proto".languageCode = data and data.Wikipedia_code or languageCodelocal italicize = script == "Latn" and italicsif not text then text = "[text?]" endlocal textDirectionMarkers = { "", "", "" }if data and data["direction"] == "rtl" thentextDirectionMarkers = { ' dir="rtl"', '‏', '‎' }endlocal out = { textDirectionMarkers[2] }if italicize thentable.insert(out, "<i lang=\"" .. languageCode .. "\"" .. textDirectionMarkers[1] .. ">" .. text .. "</i>")elsetable.insert(out, "<span lang=\"" .. languageCode .. "\"" .. textDirectionMarkers[1] .. ">" .. text .. "</span>")endtable.insert(out, textDirectionMarkers[3])return table.concat(out)endfunction p.lang(frame)local parent = frame:getParent()local args = parent.args[1] and parent.args or frame.argslocal codes = args[1] and mw.text.trim(args[1])local text = args[2] or error("Provide text in the second parameter")local languageCode, scriptCode, errorText = getCodes(codes, text)local italics = args.italics or args.i or args.italicitalics = not (italics == "n" or italics == "-" or italics == "no")return tag(text, languageCode, scriptCode, italics) .. errorTextendlocal function linkToWiktionary(entry, linkText, languageCode)local data = langData[languageCode]local nameif languageCode thenif data and data.name thenname = data.nameelse-- On other languages' wikis, use mw.getContentLanguage():getCode(),-- or replace 'en' with that wiki's language code.name = mw.language.fetchLanguageName(languageCode, 'en')if name == "" thenerror("Name for the language code " .. ("%q"):format(languageCode or nil).. " could not be retrieved with mw.language.fetchLanguageName, ".. "so it should be added to [[Module:Language/data]]")endendif entry:sub(1, 1) == "*" thenif name ~= "" thenentry = "Reconstruction:" .. name .. "/" .. entry:sub(2)elseerror("Language name is empty")endelseif data and data.type == "reconstructed" thenmw.log("Reconstructed language without asterisk:", languageCode, name, entry)local frame = mw.getCurrentFrame()-- Track reconstructed entries with no asterisk by transcluding-- a nonexistent template. This technique is used in Wiktionary:-- see [[wikt:Module:debug]].-- [[Special:WhatLinksHere/tracking/wikt-lang/reconstructed with no asterisk]]pcall(frame.expandTemplate, frame,{ title = 'tracking/wikt-lang/reconstructed with no asterisk' })if name ~= "" thenentry = "Reconstruction:" .. name .. "/" .. entryelseerror("Language name is empty")endelseif data and data.type == "appendix" thenif name ~= "" thenentry = "Appendix:" .. name .. "/" .. entryelseerror("Language name is empty")endendif entry and linkText thenreturn "[[wikt:" .. entry .. "#" .. name .. "|" .. linkText .. "]]"elseerror("linkToWiktionary needs a Wiktionary entry or link text, or both")endelsereturn "[[wikt:" .. entry .. "|" .. linkText .. "]]"endendfunction p.wiktlang(frame)local parent = frame:getParent()local args = parent.args[1] and parent.args or frame.argslocal codes = args[1] and mw.text.trim(args[1])local word1 = ifNotEmpty(args[2])local word2 = ifNotEmpty(args[3])if not args[2] thenerror("Parameter 2 is required")endlocal languageCode, scriptCode, errorText = getCodes(codes, word2 or word1)local italics = args.italics or args.i or args.italicitalics = not (italics == "n" or italics == "-" or italics == "no")local entry, linkTextif word2 and word1 thenentry = makeEntryName(word1, languageCode)linkText = word2elseif word1 thenentry = makeEntryName(word1, languageCode)linkText = word1endlocal outif languageCode and entry and linkText thenout = tag(linkToWiktionary(entry, linkText, languageCode), languageCode, scriptCode, italics)elseif entry and linkText thenout = linkToWiktionary(entry, linkText)elseout = '<span style="font-size: smaller;">[text?]</span>'endif out and errorText thenreturn out .. errorTextelsereturn errorText or error("The function wiktlang generated nothing")endendfunction p.wikt(frame)local parent = frame:getParent()local args = parent.args[1] and parent.args or frame.argslocal codes = args[1] and mw.text.trim(args[1])local word1 = ifNotEmpty(args[2])local word2 = ifNotEmpty(args[3])if not word1 thenerror("Provide a word in parameter 2.")endlocal languageCode, scriptCode, errorText = getCodes(codes, word1)local entry, linkTextif word2 and word1 thenentry = makeEntryName(word1, languageCode)linkText = word2elseif word1 thenentry = makeEntryName(word1, languageCode)linkText = word1endlocal outif languageCode and entry and linkText thenout = linkToWiktionary(entry, linkText, languageCode) elseif entry and linkText thenout = linkToWiktionary(entry, linkText)elseout = '<span style="font-size: smaller;">[text?]</span>'endif out and errorText thenreturn out and out .. errorTextelsereturn errorText or error("The function wikt generated nothing")endendreturn p
🔥 Top keywords: Đài Truyền hình Kỹ thuật số VTCTrang ChínhBảng xếp hạng bóng đá nam FIFAGiải vô địch bóng đá châu Âu 2024Đặc biệt:Tìm kiếmGiải vô địch bóng đá châu ÂuThích Minh TuệĐội tuyển bóng đá quốc gia RomâniaRomâniaĐội tuyển bóng đá quốc gia ÁoĐội tuyển bóng đá quốc gia SlovakiaSlovakiaĐội tuyển bóng đá quốc gia UkrainaĐội tuyển bóng đá quốc gia BỉGiải vô địch bóng đá châu Âu 2020Vòng loại giải vô địch bóng đá châu Âu 2024Đài Truyền hình Việt NamCleopatra VIIViệt NamRomelu LukakuKylian MbappéĐội tuyển bóng đá quốc gia PhápSloveniaGiải vô địch bóng đá thế giới 2022Bộ Chính trị Ban Chấp hành Trung ương Đảng Cộng sản Việt NamĐinh Tiến DũngGheorghe HagiCristiano RonaldoTô LâmBỉDanh sách phim điện ảnh Thám tử lừng danh ConanÁoGiải vô địch bóng đá châu Âu 2004Cửu Long Thành Trại: Vây thànhUkrainaThích Chân QuangKèo châu ÁĐặc biệt:Thay đổi gần đâyEuro