Module:Wikt-lang
- العربية
- Asturianu
- Авар
- Azərbaycanca
- تۆرکجه
- Basa Bali
- বাংলা
- 閩南語 / Bân-lâm-gí
- Беларуская (тарашкевіца)
- भोजपुरी
- Bikol Central
- Bosanski
- Català
- Cebuano
- الدارجة
- فارسی
- Gaeilge
- گیلکی
- ગુજરાતી
- 한국어
- हिन्दी
- Hornjoserbsce
- Bahasa Indonesia
- Jawa
- Kurdî
- Ladin
- Latina
- Македонски
- മലയാളം
- مصرى
- ဘာသာမန်
- مازِرونی
- 閩東語 / Mìng-dĕ̤ng-ngṳ̄
- Монгол
- မြန်မာဘာသာ
- Nedersaksies
- नेपाली
- ଓଡ଼ିଆ
- ਪੰਜਾਬੀ
- پښتو
- Română
- Scots
- Shqip
- Simple English
- سنڌي
- Slovenščina
- کوردی
- Српски / srpski
- Tagalog
- தமிழ்
- Taqbaylit
- တႆး
- తెలుగు
- ไทย
- ትግርኛ
- Türkçe
- Українська
- اردو
- Tiếng Việt
- 吴语
- 粵語
- 中文
- ᥖᥭᥰ ᥖᥬᥲ ᥑᥨᥒᥰ
Extended confirmed protection prevents edits from all unregistered editors and registered users with fewer than 30 days tenure and 500 edits. The policy on community use specifies that extended confirmed protection can be applied to combat disruption, if semi-protection has proven to be ineffective. Extended confirmed protection may also be applied to enforce arbitration sanctions. Please discuss any changes on the talk page; you may submit an edit request to ask for uncontroversial changes supported by consensus.
| Language templates |
|---|
| Language names (ISO 639) |
|
| Interwiki links |
| Foreign-language text |
|
| Other |
|
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}}-> language{{#invoke:Wikt-lang|wiktlang|en|language|languages}}-> languages{{#invoke:Wikt-lang|wiktlang|fr|bourguignon}}-> bourguignon{{#invoke:Wikt-lang|wiktlang|la|homō}}-> homō{{#invoke:Wikt-lang|wiktlang|grc|δημοκρατίᾱ}}-> δημοκρατίᾱ{{#invoke:Wikt-lang|wiktlang|ru|язы́к}}-> язы́к{{#invoke:Wikt-lang|wiktlang|ar|العَرَبِيَّة}}-> العَرَبِيَّة {{#invoke:Wikt-lang|wiktlang|fa|فارسی}}-> فارسی{{#invoke:Wikt-lang|wiktlang|ine-x-proto|*h2enǵh-}}-> *h2enǵh-
Invalid codes
{{#invoke:Wikt-lang|wiktlang|EN|language}}-> language{{#invoke:Wikt-lang|wiktlang|En|language|languages}}-> languages{{#invoke:Wikt-lang|wiktlang|La|homō}}-> homō{{#invoke:Wikt-lang|wiktlang|Grc|δημοκρατίᾱ}}-> δημοκρατίᾱ{{#invoke:Wikt-lang|wiktlang|Ru|язы́к}}-> язы́к{{#invoke:Wikt-lang|wiktlang|Ar|العَرَبِيَّة}}-> العَرَبِيَّة {{#invoke:Wikt-lang|wiktlang|Fa|فارسی}}-> فارسی
Errors
{{#invoke:Wikt-lang|wiktlang|en-Latin|language}}-> language [Latinis not a valid script code.]
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
Editors can experiment in this module's sandbox (edit | diff) and testcases (edit | run) pages.
Subpages of this module.
require('strict') localm_data=mw.loadData("Module:Wikt-lang/data") locallangData=m_data.languagesorm_data localp={} localfunctionifNotEmpty(value) ifvalue==""then returnnil else returnvalue end end localfunctionmakeEntryName(word,languageCode) localdata=langData[languageCode] localugsub=mw.ustring.gsub word=tostring(word) ifword==nilthen error("The function makeEntryName requires a string argument") elseifword==""then return"" else -- Remove bold and italics, so that words that contain bolding or emphasis can be linked without piping. word=word:gsub("\'\'\'","") word=word:gsub("\'\'","") ifdata==nilthen returnword else localreplacements=dataanddata["replacements"] ifreplacements==nilthen returnword else -- 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. ifreplacements.decomposethen word=mw.ustring.toNFD(word) fori,frominipairs(replacements.from)do word=ugsub( word, from, replacements.toandreplacements.to[i]or"") end else forregex,replacementinpairs(replacements)do word=ugsub(word,regex,replacement) end end returnword end end end end localfunctionfixScriptCode(firstLetter,threeLetters) returnstring.upper(firstLetter)..string.lower(threeLetters) end localfunctiongetCodes(codes) locallanguageCode,scriptCode,invalidCode localerrorText ifcodes==nilorcodes==""then errorText='no language or script code provided' elseifcodes:find("^%a%a%a?$")orcodes:find("^%a%a%a?%-%a%a%a%a$")then -- A three- or two-letter lowercase sequence at beginning of first parameter languageCode= codes:find("^%a%a%a?")and( codes:match("^(%l%l%l?)") orcodes:match("^(%a%a%a?)") :gsub("(%a%a%a?)",string.lower,1) ) -- One uppercase and three lowercase letters at the end of the first parameter scriptCode= codes:find("%a%a%a%a$")and( codes:match("(%u%l%l%l)$") orgsub( codes:match("(%a%a%a%a)$"), "(%a)(%a%a%a)", fixScriptCode, 1 ) ) elseifcodes:find("^%a%a%a?%-%a%a%a?$") orcodes:find("^%a%a%a%-%a%a%a%-%a%a%a$")then languageCode=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). elseifcodes:find("^%a%a%a?%-x%-%a%a?%a?%a?%a?%a?%a?%a?$")then languageCode,scriptCode= codes:match("^(%a%a%a%-x%-%a%a?%a?%a?%a?%a?%a?%a?)%-?(.*)$") ifnotlanguageCodethen errorText='<code>'..codes..'</code> is not a valid language or script code.' elseifscriptCode~=""andnotscriptCode:find("%a%a%a%a")then errorText='<code>'..scriptCode..'</code> is not a valid script code.' else scriptCode=scriptCode:gsub( "(%a)(%a%a%a)", fixScriptCode, 1 ) end elseifcodes:find("^%a%a%a?")then languageCode,invalidCode=codes:match("^(%a%a%a?)%-?(.*)") languageCode=string.lower(languageCode) errorText='<code>'..invalidCode..'</code> is not a valid script code.' elseifcodes:find("%-?%a%a%a%a$")then invalidCode,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.' else errorText='<code>'..codes..'</code> is not a valid language or script code.' end iferrorTextthen errorText=' <span style="font-size: smaller">['..errorText..']</span>' else errorText="" end languageCode=m_data.redirects[languageCode]orlanguageCode returnlanguageCode,scriptCode,errorText end localfunctiontag(text,languageCode,script,italicize) localdata=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=dataanddata.Wikipedia_codeorlanguageCode ifscriptandscript~=""then languageCode=languageCode.."-"..script end ifnottextthentext="[text?]"end localtextDirectionMarkers={"","",""} ifdataanddata["direction"]=="rtl"then textDirectionMarkers={' dir="rtl"','‏','‎'} end localout={textDirectionMarkers[2]} ifitalicizethen table.insert(out,"<i lang=\""..languageCode.."\""..textDirectionMarkers[1]..">"..text.."</i>") else table.insert(out,"<span lang=\""..languageCode.."\""..textDirectionMarkers[1]..">"..text.."</span>") end table.insert(out,textDirectionMarkers[3]) returntable.concat(out) end localfunctionlinkToWiktionary(entry,linkText,languageCode) localdata=langData[languageCode] localname iflanguageCodethen ifdataanddata.namethen name=data.name else -- On other languages' wikis, use mw.getContentLanguage():getCode(), -- or replace 'en' with that wiki's language code. name=mw.language.fetchLanguageName(languageCode,'en') ifname==""then error("Name for the language code "..("%q"):format(languageCodeornil) .." could not be retrieved with mw.language.fetchLanguageName, " .."so it should be added to [[Module:Wikt-lang/data]]") end end ifentry:sub(1,1)=="*"then ifname~=""then entry="Reconstruction:"..name.."/"..entry:sub(2) else error("Language name is empty") end elseifdataanddata.type=="reconstructed"then mw.log("Reconstructed language without asterisk:",languageCode,name,entry) localframe=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'}) ifname~=""then entry="Reconstruction:"..name.."/"..entry else error("Language name is empty") end elseifdataanddata.type=="appendix"then ifname~=""then entry="Appendix:"..name.."/"..entry else error("Language name is empty") end end ifentryandlinkTextthen return"[[wikt:"..entry.."#"..name.."|"..linkText.."]]" else error("linkToWiktionary needs a Wiktionary entry or link text, or both") end else return"[[wikt:"..entry.."|"..linkText.."]]" end end functionp.wiktlang(frame) localparent=frame:getParent() localargs=parent.args[1]andparent.argsorframe.args localcodes=args[1]andmw.text.trim(args[1]) localword1=ifNotEmpty(args[2]) localword2=ifNotEmpty(args[3]) ifnotargs[2]or''==args[2]then return'<span style="color:#d33">[text?] Parameter 2 is required</span>'; end locallanguageCode,scriptCode,errorText=getCodes(codes) localitalics=args.italicsorargs.iorargs.italic italics=not(italics=="n"oritalics=="-"oritalics=="no") localentry,linkText ifword2andword1then entry=makeEntryName(word1,languageCode) linkText=word2 elseifword1then entry=makeEntryName(word1,languageCode) linkText=word1 end localitalicize=italicsand(scriptCode=="Latn"orrequire("Module:Unicode data").is_Latin(linkText)) localout iflanguageCodeandentryandlinkTextthen out=tag(linkToWiktionary(entry,linkText,languageCode),languageCode,scriptCode,italicize) elseifentryandlinkTextthen out=linkToWiktionary(entry,linkText) else out='<span style="font-size: smaller;">[text?]</span>' end ifoutanderrorTextthen returnout..errorText else returnerrorTextorerror("The function wiktlang generated nothing") end end returnp