Zum Inhalt springen

Wikipedia:Lua/Modul/Sort/en

aus Wikipedia, der freien Enzyklopädie
Dies ist eine alte Version dieser Seite, zuletzt bearbeitet am 28. Oktober 2019 um 23:53 Uhr durch PerfektesChaos (Diskussion | Beiträge) (Setup). Sie kann sich erheblich von der aktuellen Version unterscheiden.
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Vorlagenprogrammierung Diskussionen Lua Test Unterseiten
Modul Deutsch English

Modul: Dokumentation

Sort – module with auxilary functions to create sortable keys.

Functions for templates

  • All functions evaluate the first parameter as term to be sorted.
    • If there is no first parameter provided by #invoke the first parameter of surrounding template transclusion will be used.
  • Optional parameters of #invoke specify input and result format and further capabilities.

Return value is always the sort key.

Tlatin

Alphanumeric terms in latin based scripts are reduced to basic characters of ASCII set.

Optional parameters
v
Variant
Default: ISO (simplify all diacritic characters; ligatures of two letters)
  • Various typografic codes for spaces, horizontal dashes and invisible characters are reduced to ASCII.
  • Multiple whitespace is reduced to single space.

Casing (upcased/downcased) will remain; that can be eliminated easily from result.

Tn

Numerical values.

Remarks
A sort key shall be inserted into a lexical set and correct order ensured by leading zero digits. Negative values are to be ordered in correct lexical sequence.
Minus signs may precede as ASCII or Unicode (U+2212, 872210); leading plus sign will be ignored.
Optional parameters
d
decimal separator
Default: ASCII dot
t
grouping separator (one or two).
Simultaneous request of dot and apostrophe is possible for German/Swiss segmentation.
Default: none
z
number of leading digits, die links mit Nullen aufgefüllt werden
Default: 15
m
Negative Werte zusammenhalten, aber nach Betrag sortieren
Default: Alle Zahlen nach Wert aufsteigend

Siehe auch die Auskopplung Sort/N15 zur Performance-Optimierung.

failsafe

Purpose
Version ID (local): 2024-06-14
Optional parameter:
  • 1 – Minimum version or wikidata
{{#invoke:Sort|failsafe}} yields 2024-06-14
With a parameter as ISO date it is compared whether the current module satisfies this version or later.
  • {{#invoke:Sort|failsafe|2001-01-01}} returns: »2024-06-14«
  • {{#invoke:Sort|failsafe|2099-01-01}} returns: »« – (empty), if minimal version condition not matched
  • If keyword is wikidata, result is version ID registered on Wikidata (2024-06-14) or local if not found there.
  • If keyword is ~, result is empty if local and Wikidata version are the same: ().
Returns:
  • Empty, if minimal version condition not matched, or ~ and local version is synchronized.
  • Version ID if no parameter, or if wikidata, or local if not found there, or not synchronized.

Examples (test page)

A test page illustrates results on input formats.

Date and time

That is implemented by the module DateTime.

Functions for Lua modules (API)

All functions described above can be used by other modules:

local lucky, Sort = pcall( require, "Module:Sort" )
if type( Sort ) == "table" then
    Sort = Sort.Sort()
else
    -- In the event of errors, Sort is an error message.
    return "<span class='error'>" .. Sort .. "</span>"
end
Sort.lex( adjust, apply, adapt )
Similar to Tlatin.
adjust
term (string)
mandatory
apply
base script (string)
  • "latin"
  • "cyrillic"
  • "greek"
  • "uni"
currently latin available only
adapt
variant (string, optional)
  • "DIN5007m2"
Sort.num( value, d, t, z, m )
Similar to Tn.
value
numerical value (string, number)
mandatory
d
decimal separator (string)
t
one or two grouping separators (string)
z
number of leading digits (number)
m
numerical values vertically aligned by amount (boolean)
Sort.failsafe( atleast )
Versioning interface similar to failsafe
atleast
optional
nil or minimum version or wikidata or ~ for synchronisation
returns: Version ID as string or false

Installation on other WMF projects

Follow the steps:

  1. Copy main module Module:Sort into your project.
    • If possible keep the name Sort.
    • If another name is required due to conflict or naming convention or non-latin script then choose a different one.
  2. Register this module at d:Q24205172.
  3. Copy desired sub modules, and keep the chosen root name.
  4. Ready.
  5. Consider translation of doc page.

Usage

General library; no limitations.

Dependencies

No other than sub modules.

Sub modules

Envisioned

  • Module:Sort/cyrillic – containing collation table for cyrillic based scripts (Ukrainian etc.).
  • Module:Sort/greek – containing collation table for greek scripts (polytonic).
  • Module:Sort/uni – containing collation table for all (letter based?) script systems.

Internationalisation

Not necessary.