Module:headword: difference between revisions
can now input multiple tracking codes in one call of "track" |
trying to fix the problem mentioned at Wiktionary:Grease pit/2017/June#Category:head tracking/no lang category |
||
Line 425: | Line 425: | ||
for _, cat in ipairs(data.categories) do |
for _, cat in ipairs(data.categories) do |
||
-- Does the category begin with the language name? If not, tag it with a tracking category. |
-- Does the category begin with the language name? If not, tag it with a tracking category. |
||
if not mw.ustring.find(cat, "^" .. data.lang:getCanonicalName()) then |
if not mw.ustring.find(cat, "^" .. require("Module:string").pattern_escape(data.lang:getCanonicalName())) then |
||
mw.log(cat, data.lang:getCanonicalName()) |
|||
table.insert(tracking_categories, "head tracking/no lang category") |
table.insert(tracking_categories, "head tracking/no lang category") |
||
Revision as of 03:19, 26 June 2017
- The following documentation is located at Module:headword/documentation. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module is used to show headword lines, along with any annotations like genders, transliterations and inflections. It's used by the template {{head}}
, via the submodule Module:headword/templates. It's also used by many other headword modules; for a full list, see Category:Headword-line modules. Some of the data used by this module is found in Module:headword/data.
export.full_headword
function export.full_headword(data)
This function lacks documentation. Please add a description of its usages, inputs and outputs, or its difference from similar functions, or make it local to remove it from the function list.
Further explanations for full_headword()
The sole argument, data
, is a table containing the following items (WARNING: they will be destructively modified):
{
lang = language_object,
pagename = nil or "pagename",
heads = { "head1", "head2", "head3", ... } or {
{
term = nil or "head1",
tr = nil or "translit1",
ts = nil or "transcription1",
sc = nil or script_object,
q = nil or {"left_qualifier1", "left_qualifier2", ...},
qq = nil or {"right_qualifier1", "right_qualifier2", ...},
refs = nil or {{text = "ref_text1" or "", name = nil or "ref_name1", group = nil or "ref_group1"}, ...},
separator = nil or "separator",
},
...
},
translits = { [1] = "translit1", [3] = "translit3", ... },
transcriptions = { [2] = "transcription2", [3] = "transcription3", ... },
sc = script_object,
inflections = {
enable_auto_translit = boolean,
{ label = "grammatical_category", "inflected_form1", "inflected_form2", ... },
{ label = "grammatical_category", accel = {form = "tag|tag", lemma = "lémma"}, "inflected_form1", "inflected_form2", ... },
{
label = "grammatical_category",
accel = {
form = "tag|tag",
target = "form_target",
tr = nil or "form_manual_translit",
gender = "gender_spec" or {"gender_spec1", "gender_spec2", ...},
pos = "form_part_of_speech",
lemma = nil or "lémma",
lemma_translit = nil or "lemma_manual_translit",
no_store = boolean,
},
sc = nil or inflection_specific_script_object,
enable_auto_translit = boolean,
"inflected_form1",
{
term = "inflected_form2",
alt = nil or "display_text",
translit = nil or "manual_transliteration",
transcription = nil or "manual_transcription",
genders = {"gender1", "gender2", {spec = "gender3", qualifiers = nil or {"qualifier1", "qualifier2", ... }}},
accel = {form = "tag|tag|tag", lemma = "lemma_of_inflected_form", lemma_translit = "manual_translit" },
lang = nil or term_specific_lang_object,
sc = nil or term_specific_script_object,
id = "sense_id",
gloss = "gloss",
pos = "part_of_speech",
lit = "literal meaning",
q = nil or {"left_qualifier1", "left_qualifier2", ... },
qq = nil or {"right_qualifier1", "right_qualifier2", ... },
refs = nil or {{text = "ref_text1" or "", name = nil or "ref_name1", group = nil or "ref_group1"}, ...},
separator = nil or "separator",
nolinkinfl = boolean,
face = nil or "plain" or "hypothetical",
},
{
label = "raw_textual_label",
q = nil or {"left_qualifier1", "left_qualifier2", ... },
qq = nil or {"right_qualifier1", "right_qualifier2", ... },
refs = nil or {{text = "ref_text1" or "", name = nil or "ref_name1", group = nil or "ref_group1"}, ...},
separator = nil or "separator",
},
...
},
{ label = "grammatical_category", request = true },
...
},
genders = {
"gender1",
{spec = "gender2", qualifiers = {"qualifier1", "qualifier2", ...}},
...
},
pos_category = "plural_part_of_speech",
categories = { "category1", "category2", ... },
whole_page_categories = { "category1", "category2", ... },
force_cat_output = boolean,
sccat = boolean,
noposcat = boolean,
nogendercat = boolean,
nomultiwordcat = boolean,
nopalindromecat = boolean,
nolinkhead = boolean,
nolinkinfl = boolean,
sort_key = "sort_key",
id = "sense_id",
}
Further explanation:
data.lang
is required and is a language object from Module:languages corresponding to a given language. For example, userequire("Module:languages").getByCode("ru")
to retrieve the object corresponding to Russian.data.pagename
is optional and allows you to override the pagename used variously in the module (e.g. as the default value when a head is omitted, for setting categories such as palindromes andterms spelled with CHAR
, etc.).data.heads
is a table listing the heads of the headword. Each element is either a string specifying only the headword itself (old-style), or an object specifying all the properties of the headword (new-style). You cannot mix and match these two styles; all elements should be of one type or the other. If no heads are specified at all (data.heads
is omitted or is an empty array), a default head is set based on the assumed pagename (either the actual pagename or the value ofdata.pagename
, if set). When using old-style head strings, a given head in the array can benil
, in which case a default head is set as above. When head objects are used, a given object can have the following properties:.term
: A string specifying the headword. This can be omitted, in which case a default head is set as above. Explicit headwords are generally used to specify extra diacritics (in languages with such diacritics, e.g. Russian, Arabic, Latin, Ancient Greek, Old English, etc.), or to link individual words of a multiword term, particularly when the words are inflected forms. Note that by default, each word is linked individually to itself, so there is no need to specify links for a term like a golden key can open any door. Some additional notes:- If a headword string contains wikilinks, they are converted into language-section links for the given language (using
Module:links#language_link
, which is also used by{{l}}
). For example, giving"[[give]] [[up]]"
, if the language provided is English, will produce:"[[give#English|give]] [[up#English|up]]"
. If string is prefixed with * or if any of the links are, then they are interpreted as reconstructed terms and it will create links to the Reconstruction namespace as appropriate. - If the page name contains spaces or punctuation marks (except for punctuation marks that are used inside of words), it is split and each individual word is automatically wikilinked as above.
- If the current page is in the
Reconstruction:
namespace, then an asterisk"*"
will be prepended to the headword to indicate that it is a reconstructed term.
- If a headword string contains wikilinks, they are converted into language-section links for the given language (using
.tr
: A string specifying the transliteration of the headword. This is only needed when the headword is in a non-Latin script, and even then only when the automatic transliteration specified using the language's transliteration module is incorrect (or the language has no transliteration module, such as with Persian and Hebrew). For languages with a transliteration module, pass in"-"
to suppress the transliteration entirely..ts
: A string specifying the transcription of the headword. This is only used in a few languages with non-Latin scripts where the spelling is significantly different from the pronunciation, such as Akkadian, Old Persian or Hittite. In cases like this, the transliteration usually reflects the spelling and the transcription reflects the pronunciation. For this reason, transcriptions are displayed between slashes. Transcriptions should NOT be used simply to display IPA pronunciation of a language like Russian or Arabic. Unlike for transliterations, there are no automatic transcription modules..sc
: An optional script object from Module:scripts corresponding to a given script, specifying the script that the headword is in. If omitted, defaults to the top-leveldata.sc
value. Most of the time, neither the per-headword script nor top-level script need to be specified: If both are omitted, Module:scripts will determine the script(s) using the list of scripts in the language's data file and the characters that are in the headword. Specifically, if there are multiple possible scripts for a language, the script with the largest number of characters in the headword is chosen..q
: An optional array specifying one of more qualifiers displayed to the left of the headword. Qualifiers are displayed in italics and with parentheses around them, and are intended to specify relevant properties of the headword, especially when there is more than one headword..qq
: An optional array specifying one of more qualifiers displayed to the right of the headword, as above..refs
: An optional array specifying one of more references (i.e. footnotes) for the headword. This is similar to using<ref>...</ref>
to specify a reference/footnote after a given word in the text. Each element of the array is either a string (the text of the reference) or an object of the form{text = "ref_text" or "", name = nil or "ref_name", group = nil or "ref_group"}
. In this latter format:.text
specifies the reference text (which cannot benil
; use a blank string when cross-referencing to another reference);.name
gives an optional name to the reference for cross-reference purposes, if the reference text is non-empty, similarly to<ref name="ref_name">ref_text</ref>
; however, if the reference text is empty, it specifies a cross-reference to a previously-named reference, similarly to<ref name="ref_name"/>
;.group
gives an optional group to the reference for grouping purposes, similarly to<ref name="ref_name" group="ref_group">ref_text</ref>
; however, if the reference text is empty, it specifies the group of a cross-reference to a previously-named reference, similarly to<ref name="ref_name" group="ref_group"/>
.
.separator
: The separator preceding the headword. If omitted, the default value is<i>or</i>
(i.e. the italicized word or surrounded by spaces) for the second and higher headword, and a blank string for the first headword. Use a blank string to request no separator at all.
data.translits
is an optional table listing the transliterations corresponding to each headword indata.heads
, when old-style head strings are used; omitting this field is equivalent to setting it to an empty list. If new-style head objects are used, this field must be omitted. The Nth numbered entry should be either a string specifying the transliteration of headword N, or may be omitted, as with the.tr
property described above. Note that, if there are multiple headwords, the table indata.translits
might have entries in the middle of the list that arenil
. A list of this sort cannot be created withtable.insert()
, as attempting to insertnil
this way does nothing. Instead, each transliteration must be explicitly assigned using a number as index, e.g.{ [1] = "string", [3] = "string", ... }
; here, item2
isnil
, because no value was assigned to it.data.transcriptions
is an optional table listing the transcriptions corresponding to each headword indata.heads
, when old-style head strings are used; omitting this field is equivalent to setting it to an empty list. If new-style head objects are used, this field must be omitted. It is of the same format asdata.translits
, and can have holes in it as needed. The meaning of the transcription field is as described abobe for.ts
.data.sc
is an optional script object from Module:scripts corresponding to a given script. If specified, this applies equally to all heads specified usingdata.heads
; if you need to specify per-head scripts, use the head object format documented above. Most of the time you can omit this item, and Module:scripts will determine the script(s) as specified above for the.sc
headword property.data.genders
is a table listing the gender/number specifications for the headwords. This can be omitted for no genders or numbers. Each element is either a string specifying a gender/number spec, or a table of the form{spec = "gender/number_spec", qualifiers = nil or {"qualifier1", "qualifier2", ...}
. In either case, the accepted values for genders or numbers are given in Module:gender and number; examples are"m"
for masculine,"f-an-p"
for feminine animate plural and"c2"
for noun class 2 in languages such as Swahili that have noun classes. If the format with qualifiers is given, the qualifiers are displayed to the left of the gender/number specification. Categories are automatically added according to the specific genders, e.g.LANG masculine nouns
for the language specified indata.lang
if the gender is masculine and the part of speech (see below) isnouns
orreconstructed nouns
. To suppress the addition of these categories, specifydata.nogendercat = true
.data.inflections
is a table listing the inflections to be displayed in the headword entry. The format of this table is somewhat complex and is described below underformat_inflections
.data.pos_category
is the part-of-speech category for the entry. This is one of thelemma
andnonlemma
parts of speech listed in Module:headword/data. It should be in the plural: for example,"nouns"
. If this item is omitted, the part of speech category must be included in as the first item indata.categories
.data.categories
is a table listing the categories to which the entry containing the headword will be added. The first category should be a part-of-speech category, with the canonical name of the language at the beginning –"Russian nouns"
– unless the part of speech is given in the fielddata.pos_category
.data.whole_page_categories
is a table listing language-agnostic categories to which the page will be added, which it is nevertheless useful for the headword module to handle (e.g. Category:Unsupported titles). Because they are not tied to a language, pages in them should be sorted according to their{{DEFAULTSORT:}}
values for the sake of consistency. Note that some of these - including "Category:Unsupported titles" - are already handled automatically.data.sort_key
is a string specifying a sort key for the categories listed indata.categories
. Sort keys should usually be omitted, because theformat_categories
function in Module:utilities will generate a suitable sortkey in most cases. The sortkey is used to ensure that the page is listed in the correct order in the categories to which it belongs.data.nolinkhead
is a boolean value determining whether or not to link the individual words of a multiword headword, which is done by default.data.nolinkinfl
is a boolean value determining whether or not to link the inflections of the entire headword. Not to be confused withpart.nolinkinfl
, which disables linking only for one of the inflections. It is used, for example, by Module:la-headword for reconstructed terms.
Examples
A simple example
full_headword{
lang = require("Module:languages").getByCode("en"), -- language code
heads = {"book"}, -- headwords
inflections = {
{label = "plural", "books"} -- inflections
},
categories = {"English nouns"}, -- part-of-speech category
}
might give (depending on the page it's run on):
<strong class="Latn headword" lang="en">book</strong> (''plural'' <b class="Latn" lang="en">[[books#English|books]]</b>)[[Category:English lemmas|HEADWORD]][[Category:English nouns|HEADWORD]]
which displays as:
- book (plural books)
A fuller example
full_headword{
lang = require("Module:languages").getByCode("de"),
heads = {"Hund"},
genders = {"m"},
inflections = {
{label = "genitive", "Hundes", "Hunds"},
{label = "plural", "Hunde", {term="Hünde", q="nonstandard"}},
{label = "diminutive",
{term = "Hündchen", genders = {"n"}},
{nolinkinfl=true, term = "Hündlein", genders = {"n"}}
}
},
categories = {"German nouns"},
}
might give (depending on the page it's run on):
<strong class="Latn headword" lang="de">Hund</strong> <span class="gender"><abbr title="masculine gender">m</abbr></span> (''genitive'' <b class="Latn" lang="de">[[Hundes#German|Hundes]]</b> ''or'' <b class="Latn" lang="de">[[Hunds#German|Hunds]]</b>, ''plural'' <b class="Latn" lang="de">[[Hunde#German|Hunde]] </b>''or (nonstandard)''<b> [[Hünde#German|Hünde]]</b>, ''diminutive'' <b class="Latn" lang="de">[[Hündchen#German|Hündchen]]</b> <span class="gender"><abbr title="neuter gender">n</abbr></span> ''or'' <b class="Latn" lang="de">Hündlein</b> <span class="gender"><abbr title="neuter gender">n</abbr></span>)[[Category:German lemmas|HEADWORD]][[Category:German nouns|HEADWORD]]
which displays as:
- Hund m (genitive Hundes or Hunds, plural Hunde or (nonstandard) Hünde, diminutive Hündchen n or Hündlein n)
An example in a non-Latin script
This example is in Russian, which has automatic transliteration:
full_headword{
lang = require("Module:languages").getByCode("ru"),
heads = {"кни́га"},
genders = {"f-in"},
inflections = {
{label = "genitive", "кни́ги"},
{label = "nominative plural", "кни́ги"},
{label = "genitive plural", "книг"}
},
categories = {"Russian nouns"},
}
might give (depending on the page it's run on):
<strong class="Cyrl headword" lang="ru">кни́га</strong> [[Wiktionary:Russian transliteration|•]] (<span class="tr" lang=""><span class="tr" lang="">kníga</span></span>) <span class="gender"><abbr title="feminine gender">f</abbr> <abbr title="inanimate">inan</abbr></span> (''genitive'' <b class="Cyrl" lang="ru">[[книги#Russian|кни́ги]]</b>, ''nominative plural'' <b class="Cyrl" lang="ru">[[книги#Russian|кни́ги]]</b>, ''genitive plural'' <b class="Cyrl" lang="ru">[[книг#Russian|книг]]</b>)[[Category:Russian lemmas|HEADWORD]][[Category:Russian nouns|HEADWORD]]
which displays as
Note a few things about the transliteration:
- If the transliteration is specified and non-empty, Module:headword adds some stuff before and after it. For example, if the transliteration is
"foo"
and the language is Hebrew, produceswhich looks like “• (foo)”.[[Wiktionary:Hebrew transliteration|•]] (<span lang="">foo</span>)
- The bullet linking to a transliteration policy page is only added if the page actually exists.
A fuller example in a non-Latin script
This example is in Russian, with two headwords, each of which requires manual transliteration:
full_headword{
lang = require("Module:languages").getByCode("ru"),
heads = {
{term = "интервьюе́р", tr = "intɛrvʹjuér"},
{term = "интервью́ер", "intɛrvʹjújer"},
},
genders = {"m-an"},
inflections = {
{label = "genitive", "интервьюе́ра", "интервью́ера"},
{label = "nominative plural", "интервьюе́ры", "интервью́еры"},
{label = "genitive plural", "интервьюе́ров", "интервью́еров"},
},
categories = {"Russian nouns"},
}
might give (depending on the page it's run on):
<strong class="Cyrl headword" lang="ru">интервьюе́р</strong> ''or'' <strong class="Cyrl headword" lang="ru">интервью́ер</strong> [[Wiktionary:Russian transliteration|•]] (<span class="tr" lang=""><span class="tr" lang="">intɛrvʹjuér</span> ''or'' <span class="tr" lang="">intɛrvʹjújer</span></span>) <span class="gender"><abbr title="masculine gender">m</abbr> <abbr title="animate">anim</abbr></span> (''genitive'' <b class="Cyrl" lang="ru">[[интервьюера#Russian|интервьюе́ра]]</b> ''or'' <b class="Cyrl" lang="ru">[[интервьюера#Russian|интервью́ера]]</b>, ''nominative plural'' <b class="Cyrl" lang="ru">[[интервьюеры#Russian|интервьюе́ры]]</b> ''or'' <b class="Cyrl" lang="ru">[[интервьюеры#Russian|интервью́еры]]</b>, ''genitive plural'' <b class="Cyrl" lang="ru">[[интервьюеров#Russian|интервьюе́ров]]</b> ''or'' <b class="Cyrl" lang="ru">[[интервьюеров#Russian|интервью́еров]]</b>)[[Category:Russian lemmas|HEADWORD]][[Category:Russian nouns|HEADWORD]]
which displays as
- интервьюе́р or интервью́ер • (intɛrvʹjuér or intɛrvʹjújer) m anim (genitive интервьюе́ра or интервью́ера, nominative plural интервьюе́ры or интервью́еры, genitive plural интервьюе́ров or интервью́еров)
Another fuller example in a non-Latin script
This example is in Arabic, with embedded links in the headword, manual transliteration in an inflection and use of enable_auto_translit
:
full_headword{
lang = require("Module:languages").getByCode("ar"),
heads = {
{term = "[[غُدّة]] [[بَصَلِيّ|بَصَلِيّة]] [[إحْلِيلِيّ|إحْلِيلِيّة]]", tr = "ḡudda baṣaliyya ʾiḥlīliyya"},
},
genders = {"f"},
inflections = {
enable_auto_translit = true,
{label = "plural", {term="غُدَد بَصَلِيَّة إِحْلِيلِيَة", translit="ḡudad baṣaliyya ʾiḥlīliyya"}},
},
categories = {"Arabic nouns"},
}
might give (depending on the page it's run on):
<strong class="Arab headword" lang="ar">[[غدة#Arabic|غُدّة]] [[بصلي#Arabic|بَصَلِيّة]] [[إحليلي#Arabic|إحْلِيلِيّة]]</strong> [[Wiktionary:Arabic transliteration|•]] (<span class="tr" lang=""><span class="tr" lang="">ḡudda baṣaliyya ʾiḥlīliyya</span></span>) <span class="gender"><abbr title="feminine gender">f</abbr></span> (''plural'' <b class="Arab" lang="ar">[[غدد بصلية إحليلية#Arabic|غُدَد بَصَلِيَّة إِحْلِيلِيَة]]</b> (<span lang="" class="tr">ḡudad baṣaliyya ʾiḥlīliyya</span>))[[Category:Arabic lemmas|HEADWORD]][[Category:Arabic nouns|HEADWORD]]
which displays as
- غُدّة بَصَلِيّة إحْلِيلِيّة • (ḡudda baṣaliyya ʾiḥlīliyya) f (plural غُدَد بَصَلِيَّة إِحْلِيلِيَة (ḡudad baṣaliyya ʾiḥlīliyya))
Proposed/planned changes
- Checking for invalid genders, given a list of genders that are valid for a particular language.
local export = {}
local m_data = mw.loadData("Module:headword/data")
local isLemma = m_data.lemmas
local isNonLemma = m_data.nonlemmas
local notranslit = m_data.notranslit
local toBeTagged = m_data.toBeTagged
local parameters = {
lang = { type = "object" },
script = { type = "object" },
heads = { type = "table" },
translits = { type = "table" },
inflections = { type = "table" },
genders = { type = "table" },
categories = { type = "table" },
pos_category = { type = "string" },
sort_key = { type = "string" },
id = { type = "string" },
}
local function preprocess(data)
--[=[
[[Special:WhatLinksHere/Template:tracking/headword/heads-not-table]]
[[Special:WhatLinksHere/Template:tracking/headword/translits-not-table]]
]=]
if type(data.heads) ~= "table" then
if data.heads then
require("Module:debug").track("headword/heads-not-table")
end
data.heads = { data.heads }
end
if type(data.translits) ~= "table" then
if data.translits then
require("Module:debug").track("headword/translits-not-table")
end
data.translits = { data.translits }
end
if not data.heads or #data.heads == 0 then
data.heads = {""}
end
local title = mw.title.getCurrentTitle()
-- Determine if term is reconstructed
local is_reconstructed = data.lang:getType() == "reconstructed"
or title.nsText == "Reconstruction"
-- Create a default headword.
local subpagename = title.subpageText
local pagename = title.text
local default_head
if is_reconstructed then
default_head = require("Module:utilities").plain_gsub(pagename, data.lang:getCanonicalName() .. "/", "")
else
default_head = subpagename
end
-- Add links to multi-word page names when appropriate
if data.lang:getCode() ~= "zh" then
local spacingPunctuation = "([%s%p]+)"
--[[ Variable containing anything that is
not a punctuation character found inside of words.
Used to exclude characters from the above regex. ]]
local notWordPunc = "([^-־׳״'.·*]+)"
local contains_words = false
for possibleWordBreak in mw.ustring.gmatch(default_head, spacingPunctuation) do
if mw.ustring.find(possibleWordBreak, notWordPunc) then
contains_words = true
break
end
end
if (not is_reconstructed) and contains_words then
local function workaround_to_exclude_chars(s)
return mw.ustring.gsub(s, notWordPunc, "]]%1[[")
end
default_head = "[["
.. mw.ustring.gsub(
default_head,
spacingPunctuation,
workaround_to_exclude_chars
)
.. "]]"
--[=[
use this when workaround is no longer needed:
default_head = "[["
.. mw.ustring.gsub(default_head, WORDBREAKCHARS, "]]%1[[")
.. "]]"
Remove any empty links, which could have been created above
at the beginning or end of the string.
]=]
default_head = mw.ustring.gsub(default_head, "%[%[%]%]", "")
end
end
if is_reconstructed then
default_head = "*" .. default_head
end
-- If a head is the empty string "", then replace it with the default
for i, head in ipairs(data.heads) do
if head == "" then
head = default_head
else
if head == default_head and data.lang:getCanonicalName() == "English" then
table.insert(data.categories, data.lang:getCanonicalName() .. " terms with redundant head parameter")
end
end
data.heads[i] = head
end
--[[ Try to detect the script if it was not provided
We use the first headword for this, and assume
that all of them have the same script
This *should* always be true, right? ]]
if not data.sc then
data.sc = require("Module:scripts").findBestScript(data.heads[1], data.lang)
end
-- Make transliterations
for i, head in ipairs(data.heads) do
local translit = data.translits[i]
-- Try to generate a transliteration if necessary
-- Generate it if the script is not Latn or similar, and if no transliteration was provided
if translit == "-" then
translit = nil
elseif not translit
and not (
data.sc:getCode():find("Latn", nil, true)
or data.sc:getCode() == "Latinx"
or data.sc:getCode() == "None"
)
and (not data.sc or data.sc:getCode() ~= "Imag") then
translit = data.lang:transliterate(require("Module:links").remove_links(head), data.sc)
-- There is still no transliteration?
-- Add the entry to a cleanup category.
if not translit and not notranslit[data.lang:getCode()] then
translit = "<small>transliteration needed</small>"
table.insert(data.categories, data.lang:getCanonicalName() .. " terms needing transliteration")
end
end
-- Link to the transliteration entry for languages that require this
if translit and data.lang:link_tr() then
translit = require("Module:links").full_link{
term = translit,
lang = data.lang,
sc = require("Module:scripts").getByCode("Latn"),
tr = "-"
}
end
data.translits[i] = translit
end
if data.id and type(data.id) ~= "string" then
error("The id in the data table should be a string.")
end
end
-- Format a headword with transliterations
local function format_headword(data)
local m_links = require("Module:links")
local m_scriptutils = require("Module:script utilities")
if data.heads and #data.heads and data.lang then
require("Module:debug").track{
"headword/heads/" .. #data.heads,
"headword/heads/" .. #data.heads .. "/" .. data.lang:getCode()
}
end
-- Are there non-empty transliterations?
-- Need to do it this way because translit[1] might be nil while translit[2] is not
local has_translits = false
-- Format the headwords
for i, head in ipairs(data.heads) do
if data.translits[i] then
has_translits = true
end
-- Apply processing to the headword, for formatting links and such
if head:find("[[", nil, true) and (not data.sc or data.sc:getCode() ~= "Imag") then
head = m_links.language_link({term = head, lang = data.lang}, false)
end
-- Add language and script wrapper
if i == 1 then
head = m_scriptutils.tag_text(head, data.lang, data.sc, "head", nil, data.id)
else
head = m_scriptutils.tag_text(head, data.lang, data.sc, "head", nil)
end
data.heads[i] = head
end
local translits_formatted = ""
if has_translits then
-- Format the transliterations
for i, head in ipairs(data.heads) do
local translit = data.translits[i]
if not translit then
translit = "?"
end
translit = m_scriptutils.tag_translit(translit, data.lang:getCode(), "head")
data.translits[i] = translit
end
translits_formatted = " (" .. table.concat(data.translits, " ''or'' ") .. ")"
if mw.title.new(data.lang:getCanonicalName() .. " transliteration", "Wiktionary").exists then
translits_formatted = " [[Wiktionary:" .. data.lang:getCanonicalName() .. " transliteration|•]]" .. translits_formatted
end
end
return table.concat(data.heads, " ''or'' ") .. translits_formatted
end
local function format_genders(data)
if data.genders and #data.genders > 0 then
local gen = require("Module:gender and number")
return " " .. gen.format_list(data.genders, data.lang)
else
return ""
end
end
local function format_inflection_parts(data, parts)
local m_links = require("Module:links")
for key, part in ipairs(parts) do
if type(part) ~= "table" then
part = {term = part}
end
local qualifiers = ""
if part.qualifiers and #part.qualifiers > 0 then
qualifiers = require("Module:qualifier").format_qualifier(part.qualifiers) .. " "
-- [[Special:WhatLinksHere/Template:tracking/headword/qualifier]]
require("Module:debug").track("headword/qualifier")
end
local partaccel = part.accel
local face = part.hypothetical and "hypothetical" or "bold"
local nolink = part.hypothetical or part.nolink
-- Convert the term into a full link
-- Don't show a transliteration here, the consensus seems to be not to
-- show them in headword lines to avoid clutter.
part = m_links.full_link(
{
term = not nolink and part.term or nil,
alt = part.alt or (nolink and part.term or nil),
lang = part.lang or data.lang,
sc = part.sc or (not part.lang and data.sc),
id = part.id,
genders = part.genders,
tr = part.translit or ((not (parts.enable_auto_translit or data.lang:getCode() == "ar")) and "-" or nil)
},
face,
false
)
if parts.accel or partaccel then
part = "<span class=\"form-of lang-" .. data.lang:getCode() .. " " .. (parts.accel or "") .. " " .. (partaccel or "") .. "\">" .. part .. "</span>"
end
part = qualifiers .. part
parts[key] = part
end
local parts_output = ""
if #parts > 0 then
parts_output = " " .. table.concat(parts, " ''or'' ")
elseif parts.request then
parts_output = " <small>[please provide]</small>"
.. require("Module:utilities").format_categories(
{data.lang:getCanonicalName() .. " entries needing inflection"},
lang,
nil,
nil,
data.force_cat_output
)
end
return "''" .. parts.label .. "''" .. parts_output
end
-- Format the inflections following the headword
local function format_inflections(data)
if data.inflections and #data.inflections > 0 then
-- Format each inflection individually
for key, infl in ipairs(data.inflections) do
data.inflections[key] = format_inflection_parts(data, infl)
end
return " (" .. table.concat(data.inflections, ", ") .. ")"
else
return ""
end
end
local function show_headword_line(data)
-- Check the namespace against the language type
if mw.title.getCurrentTitle().nsText == "" then
if data.lang:getType() == "reconstructed" then
error("Entries for this language must be placed in the Reconstruction: namespace.")
elseif data.lang:getType() == "appendix-constructed" then
error("Entries for this language must be placed in the Appendix: namespace.")
end
end
local tracking_categories = {}
table.insert(data.categories, 1, data.lang:getCanonicalName() .. " " .. data.pos_category)
-- Is it a lemma category?
if isLemma[data.pos_category] or isLemma[data.pos_category:gsub("^reconstructed ", "")] then
table.insert(data.categories, 1, data.lang:getCanonicalName() .. " lemmas")
-- Is it a nonlemma category?
elseif isNonLemma[data.pos_category]
or isNonLemma[data.pos_category:gsub("^reconstructed ", "")]
or isLemma[data.pos_category:gsub("^mutated ", "")]
or isNonLemma[data.pos_category:gsub("^mutated ", "")] then
table.insert(data.categories, 1, data.lang:getCanonicalName() .. " non-lemma forms")
-- It's neither; we don't know what this category is, so tag it with a tracking category.
else
--[=[
[[Special:WhatLinksHere/Template:tracking/headword/unrecognized pos]]
]=]
table.insert(tracking_categories, "head tracking/unrecognized pos")
require("Module:debug").track{
"headword/unrecognized pos",
"headword/unrecognized pos/lang/" .. data.lang:getCode(),
"headword/unrecognized pos/pos/" .. data.pos_category
}
end
-- Preprocess
preprocess(data)
local m_links = require("Module:links")
if data.lang:getType() ~= "reconstructed" then
for _, head in ipairs(data.heads) do
if mw.title.getCurrentTitle().prefixedText ~= m_links.getLinkPage(m_links.remove_links(head), data.lang) then
--[=[
[[Special:WhatLinksHere/Template:tracking/headword/pagename spelling mismatch]]
]=]
require("Module:debug").track{
"headword/pagename spelling mismatch",
"headword/pagename spelling mismatch/" .. data.lang:getCode()
}
break
end
end
end
-- Format and return all the gathered information
return
format_headword(data) ..
format_genders(data) ..
format_inflections(data) ..
require("Module:utilities").format_categories(
tracking_categories, data.lang, data.sort_key, nil, data.force_cat_output
)
end
function export.full_headword(data)
local tracking_categories = {}
-- Script-tags the topmost header.
local display_title = ""
local pagename = mw.title.getCurrentTitle().text
if not data.sc then
data.sc = require("Module:scripts").findBestScript(pagename, data.lang)
end
if data.sc and toBeTagged[data.sc:getCode()] then
local frame = mw.getCurrentFrame()
frame:callParserFunction("DISPLAYTITLE", '<span class="' .. data.sc:getCode() .. '">' .. pagename .. '</span>')
end
if data.force_cat_output then
--[=[
[[Special:WhatLinksHere/Template:tracking/headword/force cat output]]
]=]
require("Module:debug").track("headword/force cat output")
end
if data.getCanonicalName then
error('The "data" variable supplied to "full_headword" should not be a language object.')
end
-- Were any categories specified?
if data.categories and #data.categories > 0 then
for _, cat in ipairs(data.categories) do
-- Does the category begin with the language name? If not, tag it with a tracking category.
if not mw.ustring.find(cat, "^" .. require("Module:string").pattern_escape(data.lang:getCanonicalName())) then
mw.log(cat, data.lang:getCanonicalName())
table.insert(tracking_categories, "head tracking/no lang category")
--[=[
[[Special:WhatLinksHere/Template:tracking/head tracking/no lang category]]
]=]
require("Module:debug").track{
"headword/no lang category",
"headword/no lang category/lang/" .. data.lang:getCode()
}
end
end
if not data.pos_category
and mw.ustring.find(data.categories[1], "^" .. data.lang:getCanonicalName())
then
data.pos_category = mw.ustring.gsub(data.categories[1], "^" .. data.lang:getCanonicalName() .. " ", "")
table.remove(data.categories, 1)
end
end
if not data.pos_category then
error(
'No valid part-of-speech categories were found in the list '
.. 'of categories passed to the function "full_headword". '
.. 'The part-of-speech category should consist of a language\'s '
.. 'canonical name plus a part of speech.'
)
end
-- Categorise for unusual characters
local standard = data.lang:getStandardCharacters()
if standard then
if mw.ustring.len(mw.title.getCurrentTitle().subpageText) ~= 1 and not mw.ustring.match(mw.title.getCurrentTitle().text, "^Unsupported titles/") then
for character in mw.ustring.gmatch(mw.title.getCurrentTitle().subpageText, "([^" .. standard .. "])") do
table.insert(data.categories, data.lang:getCanonicalName() .. " terms spelled with " .. mw.ustring.upper(character))
end
end
end
-- Categorise for palindromes
if mw.title.getCurrentTitle().nsText ~= "Reconstruction"
and require('Module:palindromes').is_palindrome(
mw.title.getCurrentTitle().subpageText, data.lang, data.sc
) then
table.insert(data.categories, data.lang:getCanonicalName() .. " palindromes")
end
return
show_headword_line(data) ..
require("Module:utilities").format_categories(
data.categories, data.lang, data.sort_key, nil, data.force_cat_output
) ..
require("Module:utilities").format_categories(
tracking_categories, data.lang, data.sort_key, nil, data.force_cat_output
)
end
return export