Module:Wikt-lang: Difference between revisions

Content deleted Content added
m fix lowercase Greek being replaced with capital
Wiktionary function now detects two- or three-letter lowercase language codes and script codes of one uppercase and three lowercase letters, if they are placed after a hyphen
Line 1:
require('Module:No globals')
 
local p = {}
 
local gsub = mw.ustring.gsub
local find = mw.ustring.find
local match = mw.ustring.match
local U = mw.ustring.char
 
Line 158 ⟶ 163:
 
]]
 
local p = {}
 
local gsub = mw.ustring.gsub
 
local function checkForString(variable)
Line 201 ⟶ 202:
end
 
local function languageSpan(languageCode, text, script, italics)
local languageData = data[languageCode]
local script = script or languageData and languageData["scripts"][1] or "unknown"
local italicize = ( (script == "unknown" and italics == "yes") or (script == "Latn" and italics ~= "no") ) and "yes" or "no"
local out = italicize == "no" and "<span lang=\"" .. languageCode .. "\" xml:lang=\"" .. languageCode .. "\">" .. text .. "</span>" or italicize == "yes" and "<i lang=\"" .. languageCode .. "\" xml:lang=\"" .. languageCode .. "\">" .. text .. "</i>"
Line 213 ⟶ 214:
end
 
local function wiktionaryLink(languageCode, entry, linkText, script, italics)
local languageData, languageName = {}, ""
if languageCode then
languageName = mw.language.fetchLanguageName(languageCode, 'en') -- On other languages' wikis, use mw.getContentLanguage():getCode(), or replace with that wiki's language code.
if entry and linkText then
return languageSpan(languageCode, "[[wikt:" .. entry .. "#" .. languageName .. "|" .. linkText .. "]]", script, italics)
else
error("wiktionaryLink needs a Wiktionary entry or link text, or both")
Line 228 ⟶ 229:
 
function p.wikt(frame)
local languageCode = match(frame.args[1], "^%l%l%l")or match(frame.args[1], "^%l%l")
local script = match(frame.args[1], "%-(%u%l%l%l)") or nil
local word1 = frame.args[2]
local word2 = frame.args[3]
Line 246 ⟶ 248:
error("Please provide a language code in the first parameter")
end
return wiktionaryLink(languageCode, entry, linkText, script, italics)
end