Module:User:Jberkel/headword/documentation

From Wiktionary, the free dictionary
Jump to navigation Jump to search

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.

full_headword

[edit]

This is the primary external entry point. NOTE: The values passed in below will be destructively modified. You are warned.

function export.full_headword(lang, sc, heads, translits, genders, inflections, categories, sort_key)

This is used to display an entire headword line, such as will be displayed by {{head}} or various language-specific headword templates (e.g. {{ru-adj}} for Russian adjectives, {{de-noun}} for German nouns, etc.). Arguments are as follows (WARNING: they will be destructively modified):

  • lang is required and is a language object corresponding to a given language. Use e.g. require("Module:languages").getByCode("ru") to retrieve the object corresponding to Russian.
  • sc is a script object corresponding to a given script. Most of the time you can pass in nil.
  • heads is a table listing the heads of the headword, each of which is a string. An empty string means to use a default head based on the page name. It is also possible to pass in a single string for a single headword, or nil, which is equivalent to passing in a single empty string (i.e. only one head, based on the page name).
  • translits is a table listing the transliterations corresponding to each headword in heads. The Nth numbered entry should be either a string specifying the transliteration of headword N, or nil for no transliteration (for some languages, this means to generate an automatic transliteration, and "-" will have to be passed in to suppress the transliteration entirely). It is also possible to pass in a single string (equivalent to a one-element list) or nil (equivalent to a no-element list). Note that, if there are multiple headwords, the table in translits might have entries in the middle of the list that are nil. A list of this sort cannot be created with table.insert(), as attempting to insert nil this way does nothing. Instead, the correct numbered entries will have to be directly assigned to.
  • genders is a table listing the gender/number strings for the headwords. This can be nil for no genders/numbers. The individual gender/number strings are as in Module:gender and number. See format_genders below for an example of this argument (it has the same format as the data.genders argument to that function).
  • 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 under format_inflections (it has the same format as the data.inflections argument to that function).
  • categories is a table listing the categories to which the page containing the headword belongs. The first category should be a part-of-speech category (e.g. "Russian adjectives").
  • sort_key is a string specifying a sort key for the categories listed in categories, or nil to use a default sort key based on the page name. This is used to ensure that the page is listed in the correct order in the categories to which it belongs. See format_categories() in Module:utilities for more information.

Examples

[edit]

A simple example

[edit]
full_headword(
    require("Module:languages").getByCode("en"),       -- language code
    nil,                                               -- no script
    {"book"},                                          -- headwords
    nil,                                               -- no translit
    nil,                                               -- no gender
    {
        {label = "plural", "books"}                    -- inflections
    }, 
    {"English nouns"}                                  -- categories
)

might give (depending on the page it's run on):

<strong class="Latn headword" lang="en">book</strong> &lrm;(''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

[edit]
full_headword(
    require("Module:languages").getByCode("de"),
    nil,
    {"Hund"},
    nil,
    {"m"},
    {
        {label = "genitive", "Hundes", "Hunds"},
        {label = "plural", "[[Hunde]] </b>''or (nonstandard)''<b> [[Hünde]]"},
        {label = "diminutive",
            {term = "Hündchen", genders = {"n"}},
            {nolink=true, term = "Hündlein", genders = {"n"}}
        }
    },
    {"German nouns"}
)

might give (depending on the page it's run on):

<strong class="Latn headword" lang="de">Hund</strong>&nbsp;<span class="gender"><abbr title="masculine gender">m</abbr></span> &lrm;(''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>&nbsp;<span class="gender"><abbr title="neuter gender">n</abbr></span> ''or'' <b class="Latn" lang="de">Hündlein</b>&nbsp;<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

[edit]

This example is in Russian, which has automatic transliteration:

full_headword(
    require("Module:languages").getByCode("ru"),
    nil,
    {"кни́га"},
    nil,
    {"f-in"},
    {
        {label = "genitive", "кни́ги"},
        {label = "nominative plural", "кни́ги"},
        {label = "genitive plural", "книг"}
    },
    {"Russian nouns"}
)

might give (depending on the page it's run on):

<strong class="Cyrl headword" lang="ru">кни́га</strong> [[Wiktionary:Russian transliteration|•]] &lrm;(<span class="tr" lang=""><span class="tr" lang="">kníga</span></span>)&nbsp;<span class="gender"><abbr title="feminine gender">f</abbr>&nbsp;<abbr title="inanimate">inan</abbr></span> &lrm;(''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

кни́га ‎(knígaf inan ‎(genitive кни́ги, nominative plural кни́ги, genitive plural книг)

A fuller example in a non-Latin script

[edit]

This example is in Russian, with two headwords, each of which requires manual transliteration:

full_headword(
    require("Module:languages").getByCode("ru"),
    nil,
    {"интервьюе́р", "интервью́ер"},
    {"intɛrvʹjuér", "intɛrvʹjújer"},
    {"m-an"},
    {
        {label = "genitive", "интервьюе́ра", "интервью́ера"},
        {label = "nominative plural", "интервьюе́ры", "интервью́еры"},
        {label = "genitive plural", "интервьюе́ров", "интервью́еров"},
    },
    {"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|•]] &lrm;(<span class="tr" lang=""><span class="tr" lang="">intɛrvʹjuér</span> ''or'' <span class="tr" lang="">intɛrvʹjújer</span></span>)&nbsp;<span class="gender"><abbr title="masculine gender">m</abbr>&nbsp;<abbr title="animate">anim</abbr></span> &lrm;(''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újerm anim ‎(genitive интервьюе́ра or интервью́ера, nominative plural интервьюе́ры or интервью́еры, genitive plural интервьюе́ров or интервью́еров)

Another fuller example in a non-Latin script

[edit]

This example is in Arabic, with embedded links in the headword and manual transliteration in an inflection (note that Arabic also has automatic transliteration, and is one of the languages that will display automatic transliterations of inflections in the headword, unlike e.g. Russian):

full_headword(
    require("Module:languages").getByCode("ar"),
    nil,
    {"[[غُدّة]] [[بَصَلِيّ|بَصَلِيّة]] [[إحْلِيلِيّ|إحْلِيلِيّة]]"},
    {"ḡudda baṣaliyya ʾiḥlīliyya"},
    {"f"},
    {
        {label = "plural", {term="غُدَد بَصَلِيَّة إِحْلِيلِيَة", translit="ḡudad baṣaliyya ʾiḥlīliyya"}},
    },
    {"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|•]] &lrm;(<span class="tr" lang=""><span class="tr" lang="">ḡudda baṣaliyya ʾiḥlīliyya</span></span>)&nbsp;<span class="gender"><abbr title="feminine gender">f</abbr></span> &lrm;(''plural'' <b class="Arab" lang="ar">[[غدد بصلية إحليلية#Arabic|غُدَد بَصَلِيَّة إِحْلِيلِيَة]]</b> &lrm;(<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īliyyaf ‎(plural غُدَد بَصَلِيَّة إِحْلِيلِيَة ‎(ḡudad baṣaliyya ʾiḥlīliyya))

format_headword

[edit]
This documentation is out of date.
The documentation on this page or section no longer reflects its current state, and some information may be missing or incorrect. Please help by editing this page, and adding information about undocumented features, while removing information that is no longer applicable.

format_headword(heads, lang, sc)

Formats a headword, using the format appropriate for the given language object and script (see Module:script utilities#tag_text).

The heads parameter can either be a single string or a table of strings. If it's a table, then each string in the table is shown as a headword, separated by "or". This allows you to show multiple alternative headwords, such as when the same written form can be accented in different ways.

It has special behaviour in certain cases as well:

  • If an item in the heads parameter 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 appendix namespace as appropriate.
  • If heads is empty (nil or the empty table), it will default to mw.title.getCurrentTitle().subpageText (equivalent to {{SUBPAGENAME}} in templates).
    • If the page name contains spaces, it is split and each individual word is automatically wikilinked as above.
    • If the current page is in the appendix namespace, and the language's type (in Module:languages) is not appendix-constructed, then a * will be prepended to the headword to indicate that it is a reconstructed term.

format_transliteration

[edit]
This documentation is out of date.
The documentation on this page or section no longer reflects its current state, and some information may be missing or incorrect. Please help by editing this page, and adding information about undocumented features, while removing information that is no longer applicable.

format_transliteration(tr, lang)

If the transliteration is specified and non-empty, adds some stuff before and after it. For example, if the transliteration is 'foo' and the language is Hebrew, produces

 [[Wiktionary:Hebrew transliteration|•]] (<span lang="">foo</span>)

which looks like “ (foo)”.

(Note: the bullet/link is only added if the linked-to page actually exists.)

format_genders

[edit]

NOTE: This documentation is up-to-date. Keep in mind, however, that this function is not currently exported, and the contents of the argument data will be overwritten.

format_genders(data)

Format gender specifications using Module:gender and number. For example:

format_genders({genders = {"m-in", "m-an-p"}, 
    lang=require("Module:languages").getByCode("ru")})

gives:

&nbsp;<span class="gender"><abbr title="masculine gender">m</abbr>&nbsp;<abbr title="inanimate">inan</abbr>, <abbr title="masculine gender">m</abbr>&nbsp;<abbr title="animate">anim</abbr>&nbsp;<abbr title="plural number">pl</abbr></span>

displays as:

 m inan, m anim pl

The argument is a table, consisting of elements .genders and .lang. NOTE: The table will be overwritten!!!

The value of .genders is a list of gender/number strings, in the form required by Module:gender and number.

format_inflections

[edit]

NOTE: This documentation is up-to-date. Keep in mind, however, that this function is not currently exported, and the contents of the argument data will be overwritten.

format_inflections(data)

Format a list (table) of inflections, which are then concatenated together with commas and surrounded by parentheses. For example:

format_inflections({inflections = {
    {label = "diminutive", "Hündchen"}
    }, lang=require("Module:languages").getByCode("de")})

gives:

&lrm;(''diminutive'' <b class="Latn" lang="de">[[Hündchen#German|Hündchen]]</b>)

displays as:

‎(diminutive Hündchen)

The argument is a table, consisting of elements .inflections, .lang, and optionally .sc. NOTE: The table will be overwritten!!!

The value of .inflections is a list of labeled inflections, each of which is a table:

  • The table must have a .label value which contains the label. It is displayed in italics and not linked.
  • The table may optionally have a .accel value. This value is used to support accelerated entry creation using WT:ACCEL. The "form-of" and "lang-(code)" classes are added automatically, so only the "(form)-form-of" class needs to be given, along with any other classes that may be needed.
  • Numbered values in the table are the actual forms. They are normally formatted in bold text and converted to a link to the term (but see below). If a term already contains a link, it is converted into a section link using Module:links#language_link, just like in format_headword.
  • Forms are optional. If the table contains only the .label, then just the label is shown with no forms. If there is more than one form, they are shown with "or" between them.

For example:

format_inflections({inflections = {
    {label = "present", "krama"},
    {label = "past", "kramade"},
    {label = "past participle", "kramat"}
    }, lang=require("Module:languages").getByCode("sv")})

format_inflections({inflections = {
    {label = "plural", accel = "plural-form-of", "voorbeelden"},
    }, lang=require("Module:languages").getByCode("nl")})

gives:

&lrm;(''present'' <b class="Latn" lang="sv">[[krama#Swedish|krama]]</b>, ''past'' <b class="Latn" lang="sv">[[kramade#Swedish|kramade]]</b>, ''past participle'' <b class="Latn" lang="sv">[[kramat#Swedish|kramat]]</b>)
 &lrm;(''plural'' <span class="form-of lang-nl plural-form-of "><b class="Latn" lang="nl">[[voorbeelden#Dutch|voorbeelden]]</b></span>)

displays as:

‎(present krama, past kramade, past participle kramat)
‎(plural voorbeelden)

It is also possible, but optional, to supply a table instead of a term. This table can contain the keys .term (the actual term), .alt (alternative display form), .sc (script), .id (sense id), .genders (list of genders), .nolink (if true, the function will not link to the term, but only display it boldfaced), .hypothetical (if true, the function will not link to the term, but display it italicized and preceded by a *), .accel (same as .accel in the outer table but applies only to the given term; if both accelerators are specified, both will appear as CSS classes). Most of these are used the same way as for full_link in Module:links, and are passed directly to it.

Example:

format_inflections({inflections = {
    {label = "diminutive",
      {term = "Hündchen", genders = {"n"}},
      {nolink=true, term = "Hündlein", genders = {"n"}}
    }}, lang=require("Module:languages").getByCode("de")})

gives:

&lrm;(''diminutive'' <b class="Latn" lang="de">[[Hündchen#German|Hündchen]]</b>&nbsp;<span class="gender"><abbr title="neuter gender">n</abbr></span> ''or'' <b class="Latn" lang="de">Hündlein</b>&nbsp;<span class="gender"><abbr title="neuter gender">n</abbr></span>)

displays as:

‎(diminutive Hündchen n or Hündlein n)

Proposed/planned changes

[edit]
  • Checking for invalid genders, given a list of genders that are valid for a particular language.