Module:Wordify/doc

MyWikiBiz, Author Your Legacy — Monday November 25, 2024
< Module:Wordify
Revision as of 08:01, 16 July 2021 by Zoran (talk | contribs) (Pywikibot 6.4.0)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This is the documentation page for Module:Wordify

This module provides a number-formatting function. This function can be used from #invoke or from other Lua modules.

This module is used by {{FXConvert}}

Use from other Lua modules

To use the module from normal wiki pages, no special preparation is needed. If you are using the module from another Lua module, first you need to load it, like this:

<syntaxhighlight lang="lua"> local mf = require('Module:Wordify') </syntaxhighlight>

(The mf variable stands for Module wordiFy; you can choose something more descriptive if you prefer.)

Most functions in the module have a version for Lua and a version for #invoke. It is possible to use the #invoke functions from other Lua modules, but using the Lua functions has the advantage that you do not need to access a Lua frame object. Lua functions are preceded by _, whereas #invoke functions are not.

main

{{#invoke:Wordify|main|x|prec=|lk=|numsys=|lang=|script=|state=|case=|class=|possessed=|person=|plural=|exclude=|simplify=}}

<syntaxhighlight lang="lua"> mf._wordify(x, prec, lk, numsys, lang, script, state, case, class, possessed, person, plural, exclude, simplify) </syntaxhighlight>

Simplify a number x using a word denoting an order of magnitude.

  • numsys can be short (short scale, the default), ind (Indian scale), or long (long scale)
  • prec is the digits of precision to output
  • if lk is true, the words will be linked to an explanation
  • lang allows to specify the locale for formatting and wording
  • script allows to specify a script if the language supports more than one
  • state can be indefinite, definite, or construct
  • case allows to specify a grammatical case
  • class allows to specify a noun class
  • if possessed is true, it designates that there are multiple possessed objects
  • person designates the person (1, 2, 3)
  • if plural is true, it indicates that the person is plural
  • exclude indicates the persons to exclude (2, 3)
  • if simplify is true, only the order of magnitude words will be output

Notes

  • The function is currently not applying declensions beyond the base case for some of the supported languages.
  • If a case that does not exist in a certain language is requested, the function may give an error or just return the base result.
  • The function understands case arguments that are not a word in a single language, like "akkusative".

Examples

Scales, links, scripts, capitalization

  • {{#invoke:Wordify|main|9876000}} displays 10 million.
  • {{#invoke:Wordify|main|9876000|lk=yes|prec=2}} displays 9.88 million.
  • {{#invoke:Wordify|main|9876000|numsys=ind}} displays 1 crore.
  • {{#invoke:Wordify|main|9876000|numsys=ind|lk=yes|prec=2}} displays 98.76 lakh.
  • {{#invoke:Wordify|main|1000000000000}} displays 1 trillion.
  • {{#invoke:Wordify|main|1000000000000|numsys=long}} displays 1 billion.
  • {{#invoke:Wordify|main|1000000000000|numsys=ind}} displays 1 lakh crore.
  • {{#invoke:Wordify|main|100000000000000}} displays 100 trillion.
  • {{#invoke:Wordify|main|100000000000000|numsys=ind}} displays 1 crore crore.
  • {{#invoke:Wordify|main|100000000000000|lang=de}} displays 100 Billionen.
  • {{#invoke:Wordify|main|100000000000000|lang=ko}} displays 100조.
  • {{#invoke:Wordify|main|100000000000000|lang=ko|script=hanja}} displays 100兆.

State, case

  • {{#invoke:Wordify|main|1000000000000|lang=sv}} displays 1 biljon.
  • {{#invoke:Wordify|main|1000000000000|lang=sv|state=d}} displays 1 biljonen.
  • {{#invoke:Wordify|main|1000000000000|lang=sv|case=g}} displays 1 biljons.
  • {{#invoke:Wordify|main|1000000000000|lang=sv|state=d|case=g}} displays 1 biljonens.
  • {{#invoke:Wordify|main|100000000000000|lang=sv}} displays 100 biljoner.
  • {{#invoke:Wordify|main|100000000000000|lang=sv|state=d}} displays 100 biljonerna.
  • {{#invoke:Wordify|main|100000000000000|lang=sv|case=g}} displays 100 biljoners.
  • {{#invoke:Wordify|main|100000000000000|lang=sv|state=d|case=g}} displays 100 biljonernas.

Simplification

  • {{#invoke:Wordify|main|1000000000|lang=fr|lk=yes}} displays 1 milliard.
  • {{#invoke:Wordify|main|1000000000|lang=fi}} displays tuhat miljoonaa.
  • {{#invoke:Wordify|main|1000000000|lang=fi|simplify=yes}} displays tuhat miljoonaa.
  • {{#invoke:Wordify|main|10000000000|lang=fi}} displays 10 tuhatta miljoonaa.
  • {{#invoke:Wordify|main|10000000000|lang=fi|simplify=yes}} displays tuhat miljoonaa.
  • {{#invoke:Wordify|main|1000000000000|lang=fi}} displays 1 biljoona.
  • {{#invoke:Wordify|main|1000000000000|lang=fi|simplify=yes}} displays biljoona.
  • {{#invoke:Wordify|main|10000000000000|lang=fi}} displays 10 biljoonaa.
  • {{#invoke:Wordify|main|10000000000000|lang=fi|simplify=yes}} displays biljoonat.

Noun class agreement

  • {{#invoke:Wordify|main|2000000|lang=la}} displays 2 millionia.
  • {{#invoke:Wordify|main|2000000|lang=la|class=n}} displays 2 millionia.
  • {{#invoke:Wordify|main|2000000|lang=la|class=m}} displays 2 milliones.
  • {{#invoke:Wordify|main|2000000|lang=la|class=f}} displays 2 milliones.

Slavic numerals

  • {{#invoke:Wordify|main|1000000|lang=sl}} displays 1 milijon.
  • {{#invoke:Wordify|main|2000000|lang=sl}} displays 2 milijona.
  • {{#invoke:Wordify|main|3000000|lang=sl}} displays 3 milijone.
  • {{#invoke:Wordify|main|4000000|lang=sl}} displays 4 milijone.
  • {{#invoke:Wordify|main|5000000|lang=sl}} displays 5 milijonov.
  • {{#invoke:Wordify|main|10000000|lang=sl}} displays 10 milijonov.
  • {{#invoke:Wordify|main|1000000000|lang=sl}} displays 1 milijarda.
  • {{#invoke:Wordify|main|2000000000|lang=sl}} displays 2 milijardi.
  • {{#invoke:Wordify|main|3000000000|lang=sl}} displays 3 milijarde.
  • {{#invoke:Wordify|main|4000000000|lang=sl}} displays 4 milijarde.
  • {{#invoke:Wordify|main|5000000000|lang=sl}} displays 5 milijard.
  • {{#invoke:Wordify|main|10000000000|lang=sl}} displays 10 milijard.
  • {{#invoke:Wordify|main|2500000|lang=sl|prec=1}} displays 2,5 milijona.
  • {{#invoke:Wordify|main|2500000000|lang=sl|prec=1}} displays 2,5 milijarde.
  • {{#invoke:Wordify|main|1000000|lang=pl}} displays 1 milion.
  • {{#invoke:Wordify|main|2000000|lang=pl}} displays 2 miliony.
  • {{#invoke:Wordify|main|3000000|lang=pl}} displays 3 miliony.
  • {{#invoke:Wordify|main|4000000|lang=pl}} displays 4 miliony.
  • {{#invoke:Wordify|main|5000000|lang=pl}} displays 5 milionów.
  • {{#invoke:Wordify|main|11000000|lang=pl}} displays 11 milionów.
  • {{#invoke:Wordify|main|12000000|lang=pl}} displays 12 milionów.
  • {{#invoke:Wordify|main|13000000|lang=pl}} displays 13 milionów.
  • {{#invoke:Wordify|main|14000000|lang=pl}} displays 14 milionów.
  • {{#invoke:Wordify|main|15000000|lang=pl}} displays 15 milionów.
  • {{#invoke:Wordify|main|21000000|lang=pl}} displays 21 milionów.
  • {{#invoke:Wordify|main|22000000|lang=pl}} displays 22 miliony.
  • {{#invoke:Wordify|main|23000000|lang=pl}} displays 23 miliony.
  • {{#invoke:Wordify|main|24000000|lang=pl}} displays 24 miliony.
  • {{#invoke:Wordify|main|25000000|lang=pl}} displays 25 milionów.
  • {{#invoke:Wordify|main|2500000|lang=pl|prec=1}} displays 2,5 miliona.
  • {{#invoke:Wordify|main|2500000000|lang=pl|prec=1}} displays 2,5 miliarda.

Possessive cases

  • {{#invoke:Wordify|main|1000000|case=possessive}} displays 1 million's.
  • {{#invoke:Wordify|main|10000000|case=possessive}} displays 10 million's.
  • {{#invoke:Wordify|main|1000000|case=possessive|simplify=yes}} displays million's.
  • {{#invoke:Wordify|main|10000000|case=possessive|simplify=yes}} displays millions'.
  • {{#invoke:Wordify|main|1000000|lang=hu|case=possessi}} displays 1 millióé.
  • {{#invoke:Wordify|main|2000000|lang=hu|case=possessi}} displays 2 millióké.
  • {{#invoke:Wordify|main|1000000000|lang=hu|case=possessi}} displays 1 milliárdé.
  • {{#invoke:Wordify|main|2000000000|lang=hu|case=possessi}} displays 2 milliárdoké.
  • {{#invoke:Wordify|main|1000000|lang=hu|case=possessi|possessed=true}} displays 1 millióéi.
  • {{#invoke:Wordify|main|2000000|lang=hu|case=possessi|possessed=true}} displays 2 milliókéi.
  • {{#invoke:Wordify|main|1000000000|lang=hu|case=possessi|possessed=true}} displays 1 milliárdéi.
  • {{#invoke:Wordify|main|2000000000|lang=hu|case=possessi|possessed=true}} displays 2 milliárdokéi.

Possessive forms

  • {{#invoke:Wordify|main|1000000|lang=hu|person=1}} displays 1 millióm.
  • {{#invoke:Wordify|main|2000000|lang=hu|person=1}} displays 2 millióim.
  • {{#invoke:Wordify|main|1000000000|lang=hu|person=1}} displays 1 milliárdom.
  • {{#invoke:Wordify|main|2000000000|lang=hu|person=1}} displays 2 milliárdaim.
  • {{#invoke:Wordify|main|1000000|lang=hu|person=2}} displays 1 milliód.
  • {{#invoke:Wordify|main|2000000|lang=hu|person=2}} displays 2 millióid.
  • {{#invoke:Wordify|main|1000000000|lang=hu|person=2}} displays 1 milliárdod.
  • {{#invoke:Wordify|main|2000000000|lang=hu|person=2}} displays 2 milliárdjaid.
  • {{#invoke:Wordify|main|1000000|lang=hu|person=3}} displays 1 milliója.
  • {{#invoke:Wordify|main|2000000|lang=hu|person=3}} displays 2 milliói.
  • {{#invoke:Wordify|main|1000000000|lang=hu|person=3}} displays 1 milliárdja.
  • {{#invoke:Wordify|main|2000000000|lang=hu|person=3}} displays 2 milliárdjai.
  • {{#invoke:Wordify|main|1000000|lang=hu|person=1|plural=yes}} displays 1 milliónk.
  • {{#invoke:Wordify|main|2000000|lang=hu|person=1|plural=yes}} displays 2 millióink.
  • {{#invoke:Wordify|main|1000000000|lang=hu|person=1|plural=yes}} displays 1 milliárdunk.
  • {{#invoke:Wordify|main|2000000000|lang=hu|person=1|plural=yes}} displays 2 millióink.
  • {{#invoke:Wordify|main|1000000|lang=hu|person=2|plural=yes}} displays 1 milliótok.
  • {{#invoke:Wordify|main|2000000|lang=hu|person=2|plural=yes}} displays 2 millióitok.
  • {{#invoke:Wordify|main|1000000000|lang=hu|person=2|plural=yes}} displays 1 milliárdotok.
  • {{#invoke:Wordify|main|2000000000|lang=hu|person=2|plural=yes}} displays 2 milliárdjaitok.
  • {{#invoke:Wordify|main|1000000|lang=hu|person=3|plural=yes}} displays 1 milliójuk.
  • {{#invoke:Wordify|main|2000000|lang=hu|person=3|plural=yes}} displays 2 millióik.
  • {{#invoke:Wordify|main|1000000000|lang=hu|person=3|plural=yes}} displays 1 milliárdjuk.
  • {{#invoke:Wordify|main|2000000000|lang=hu|person=3|plural=yes}} displays 2 milliárdjaik.

Support for additional languages

New languages can be added by creating a corresponding object.

The possessive field conforms to the following grammar:

<syntaxhighlight lang="bnf"> <possessive-rules> ::= "{}" | <string> | "{" <possessor-cases> "}" | <possessive-function> <possessor-cases> ::= <singular-possessors> | <singular-posessors> "," <plural-posessors> <singular-possessors> ::= "{" <singular-possessor-cases> "}" <singular-posessor-cases> := <simple-posessor-case> | <simple-possessor-case> "," <singular-possessor-cases> <simple-posessor-case> := "{ {" <singular-possessed> "," <plural-possessed> "} }" | <possessor-function> <singular-possessed> ::= <possessed> <plural-possessed> ::= <possessed> <possessed> ::= <string> | "{" <possessed-cases> "}" | <possessed-function> <plural-posessors> ::= "{" <plural-possessor-cases> "}" <plural-possessor-cases> := <plural-posessor-case> | <plural-possessor-case> "," <plural-possessor-cases> <plural-possessor-case> ::= "{" <clusivity-cases> "}" <clusivity-cases> ::= <simple-possessor-case> | <simple-possessor-case> "," <clusivity-cases> </syntaxhighlight>

The inflection field conforms to the following grammar:

<syntaxhighlight lang="bnf"> <inflection-rules> ::= "{}" | "{" <stem-statement> "}" | "{" <number-cases> "}" | "{" <stem-statement> "," <number-cases> "}" <stem-statement> ::= "stem" "=" <stem-function> <number-cases> ::= <number-case> | <number-case> "," <number-cases> <number-case> ::= <number-index> <number-rule> <number-index> ::= "" | "[" <integer> "]" "=" | | "[" "fraction" "]" "=" <number-rule> ::= <string> | <ending-cases-list> | <state-cases> | <number-function> <ending-cases-list> ::= "{" <ending-cases> "}" <ending-cases> ::= <ending-case> | <ending-case> "," <ending-cases> <ending-case> ::= <string-index> "=" <ending-rule> <ending-rule> ::= <string> | <class-cases-list> | <state-cases> | <ending-function> <class-cases-list> ::= "{" <class-cases> "}" <class-cases> ::= <class-case> | <class-case> "," <class-cases> <class-case> ::= <string-index> "=" <class-rule> <class-rule> ::= <string> | <grammatical-cases-list> | <state-cases> | <class-function> <state-cases> ::= "{" <indefinite-rule> "}" | "{" <indefinite-rule> "," <definite-rule> "}" | "{" <indefinite-rule> "," <definite-rule> "," <construct-rule> "}" <indefinite-rule> ::= <state-rule> <definite-rule> ::= <state-rule> <construct-rule> ::= <state-rule> <state-rule> ::= <string> | <grammatical-cases-list> | <state-function> <grammatical-cases-list> ::= "{" <grammatical-cases> "}" <grammatical-cases> ::= <grammatical-case> | <grammatical-case> "," <grammatical-cases> <grammatical-case> ::= <string-index> "=" <grammatical-rule> <grammatical-rule> ::= <string> | <simple-class-cases-list> | "{" <possessed-cases> "}" | <grammatical-function> <simple-class-cases-list> ::= "{" <simple-class-cases> "}" <simple-class-cases> ::= <simple-class-case> | <simple-class-case> "," <simple-class-cases> <simple-class-case> ::= <string-index> "=" <simple-class-rule> <simple-class-rule> ::= <string> | <simple-ending-cases-list> | <class-function> <simple-ending-cases-list> ::= "{" <simple-ending-cases> "}" <simple-ending-cases> ::= <simple-ending-case> | <simple-ending-case> "," <simple-ending-cases> <simple-ending-case> ::= <string-index> "=" <simple-ending-rule> <simple-ending-rule> ::= <string> | <ending-function> </syntaxhighlight>

Common elements:

<syntaxhighlight lang="bnf"> <possessed-cases> ::= <possessed-case> | <possessed-case> "," <possessed-cases> <possessed-case> ::= <string-index> "=" <possessed-rule> <string-index> ::= <identifier> | "[" <string> "]" <possessed-rule> ::= <string> | <possessed-function> </syntaxhighlight>

The elements <identifier>, <string>, and <integer> are as defined for the Lua language and those ending in -function are Lua functions with signatures that can be found in the code.

A certain language might not be supported by the current algorithm, in this case it should be extended for the new kind.

See also

Template:Language grammars Template:Math templates