![]() | This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
Language templates |
---|
Language names (ISO 639) |
|
Interwiki links |
Foreign-language text |
|
Other |
|
![]() | This module depends on the following other modules: |
This module is used by {{Wikt-lang}}
. It is inspired by the templates {{m}} and {{l}} and their associated modules on Wiktionary. It has a Wiktionary link function that links to the correct section of the Wiktionary entry, and applies correct language formatting and italics. The language-tagging function does most of what {{Lang}} does, except that italics can't be customized and categories aren't added.
The module uses Module:Wikt-lang/data to retrieve the language name for a language code, and to perform the necessary entry-name replacements (for instance, removing macrons from Latin entry names). These are unfortunately not automatically retrieved from Wiktionary's Wikt-lang data modules. For language codes that do not have a name
value in this module, the language name is fetched with mw.language.fetchLanguage
. When mw.language.fetchLanguage
does not fetch the correct language name (or any language name at all), please add it to Module:Wikt-lang/data, and similarly when the correct entry name is not generated, please add the entry name replacements to the module.
Examples
{{#invoke:Wikt-lang|wiktlang|en|language}}
-> Script error: The function "wiktlang" does not exist.{{#invoke:Wikt-lang|wiktlang|en|language|languages}}
-> Script error: The function "wiktlang" does not exist.{{#invoke:Wikt-lang|wiktlang|fr|bourguignon}}
-> Script error: The function "wiktlang" does not exist.{{#invoke:Wikt-lang|wiktlang|la|homō}}
-> Script error: The function "wiktlang" does not exist.{{#invoke:Wikt-lang|wiktlang|grc|δημοκρατίᾱ}}
-> Script error: The function "wiktlang" does not exist.{{#invoke:Wikt-lang|wiktlang|ru|язы́к}}
-> Script error: The function "wiktlang" does not exist.{{#invoke:Wikt-lang|wiktlang|ar|العَرَبِيَّة}}
-> Script error: The function "wiktlang" does not exist.{{#invoke:Wikt-lang|wiktlang|fa|فارسی}}
-> Script error: The function "wiktlang" does not exist.{{#invoke:Wikt-lang|wiktlang|ine-x-proto|*h₂enǵʰ-}}
-> Script error: The function "wiktlang" does not exist.
Invalid codes
{{#invoke:Wikt-lang|wiktlang|EN|language}}
-> Script error: The function "wiktlang" does not exist.{{#invoke:Wikt-lang|wiktlang|En|language|languages}}
-> Script error: The function "wiktlang" does not exist.{{#invoke:Wikt-lang|wiktlang|La|homō}}
-> Script error: The function "wiktlang" does not exist.{{#invoke:Wikt-lang|wiktlang|Grc|δημοκρατίᾱ}}
-> Script error: The function "wiktlang" does not exist.{{#invoke:Wikt-lang|wiktlang|Ru|язы́к}}
-> Script error: The function "wiktlang" does not exist.{{#invoke:Wikt-lang|wiktlang|Ar|العَرَبِيَّة}}
-> Script error: The function "wiktlang" does not exist.{{#invoke:Wikt-lang|wiktlang|Fa|فارسی}}
-> Script error: The function "wiktlang" does not exist.
Errors
{{#invoke:Wikt-lang|wiktlang|en-Latin|language}}
-> Script error: The function "wiktlang" does not exist.
Comparison of codes
Language code | Wiktionary name | English Wikipedia name |
---|---|---|
aaq | Penobscot | Eastern Abnaki |
abe | Abenaki | Western Abnaki |
ajp | South Levantine Arabic | South Levantine Arabic |
alg-pro | Proto-Algonquian | Error: unrecognized language tag: alg-pro |
apc | North Levantine Arabic | Levantine Arabic |
arb | Modern Standard Arabic | Standard Arabic |
cel-x-bryproto | Proto-Brythonic | Error: unrecognized private tag: bryproto |
cu | Old Church Slavonic | Church Slavonic |
egy | Egyptian | Ancient Egyptian |
frp | Franco-Provençal | Arpitan |
gmw-x-proto | Proto-West Germanic | Proto-West Germanic |
grk-x-proto | Proto-Hellenic | Proto-Greek |
ine-x-bsproto | Proto-Balto-Slavic | Error: unrecognized private tag: bsproto |
moe | Cree | Innu |
mul | Translingual | multiple |
nds-de | German Low German | Low German |
non-x-proto | Proto-Norse | Error: unrecognized private tag: proto |
poz-x-polproto | Proto-Nuclear Polynesian | Error: unrecognized private tag: polproto |
rw | Rwanda-Rundi | Kinyarwanda |
tts | Isan | Northeastern Thai |
xlu | Luwian | Cuneiform Luwian |
zle-x-ort | Old Ruthenian | Error: unrecognized private tag: ort |
Tracking categories
--[[ Name is the "canonical name" used on Wiktionary. Article is the Wikipedia article. Script is the ISO 15924 code. ]]
data = {
["ar"] = {
["name"] = "Arabic",
["article"] = "Arabic language",
["script"] = "Arab",
},
["en"] = {
["name"] = "English",
["article"] = "English language",
["script"] = "Latn",
},
["grc"] = {
["name"] = "Ancient Greek",
["article"] = "Ancient Greek",
["script"] = "Grek",
},
["ru"] = {
["name"] = "Russian",
["article"] = "Russian language",
["script"] = "Cyrl",
},
}
--[[
[""] = {
["name"] = "",
["article"] = "",
["script"] = "",
},
]]
f = {}
local function strip(word)
local replacements = {
["́"] = ""
}
return string.gsub(word, "́", "")
end
local function languageSpan(languageCode, text)
languageData = data[languageCode]
languageScript = languageData["script"]
if languageScript == "Latn" then
return "<i lang=\"" .. languageCode .. "\" xml:lang=\"" .. languageCode .. "\">" .. text .. "</i>"
else
return "<span lang=\"" .. languageCode .. "\" xml:lang=\"" .. languageCode .. "\">" .. text .. "</span>"
end
end
function f.lang(frame)
return languageSpan(frame.args[1], frame.args[2])
end
function wiktionaryLink(languageCode, entry, linkText)
local languageData, languageName = {}, ""
if languageCode then
languageData = data[languageCode]
if languageData == nil then
error("Language code is not recognized")
end
languageName = languageData["name"]
if entry and linkText then
return languageSpan(languageCode, "[[wikt:" .. entry .. "#" .. languageName .. "|" .. linkText .. "]]")
else
error("wiktionaryLink needs a Wiktionary entry or link text, or both")
end
else
error("wiktionaryLink needs a language code")
end
end
function f.wikt(frame)
local languageCode = frame.args[1]
local word1 = frame.args[2]
local word2 = frame.args[3]
if languageCode then
if word2 and word1 then
entry = strip(word1)
linkText = word2
elseif word1 then
entry = strip(word1)
linkText = word1
else
error("Please provide a word in the second parameter")
end
else
error("Please provide a language code in the first parameter")
end
return wiktionaryLink(languageCode, entry, linkText)
end
return f