[common-words]

Common words

Print-form snippets that write an amount of money out in words, in Ukrainian, English or German: «одна тисяча двісті тридцять чотири гривні 56 копійок». Other modules' print templates include them; the languages and the currency names live here, so a fix is a module update, not a platform release.

Try it in your workspacefree workspace · you confirm before anything installs

v0.2.0 · 23 installs · free

Print-form snippets that write an amount of money, or a plain quantity, out in words, in Ukrainian, Russian, English or German.

The platform has no number-to-words filter on purpose: the languages and the currency names live in this module, so a fix or a new currency is a module update, not a platform release. A worked template is in common-words-demo.

Amount, currency Language Result
1234.56 UAH uk одна тисяча двісті тридцять чотири гривні 56 копійок
1234.56 RUB ru одна тысяча двести тридцать четыре рубля 56 копеек
1234.56 USD en one thousand two hundred thirty-four US dollars 56 cents
1234.56 EUR de eintausendzweihundertvierunddreißig Euro 56 Cent

Use it in a print template

Set the inputs, then include the snippet. Both lines go into the template that prints the document (an invoice, a receipt, ...), not into this module:

{% assign words_amount = total %}
{% assign words_currency = currency_cd %}
{% assign words_lang = 'en' %}
{% include 'common-words.money' %}
Input Required Meaning
words_amount yes The amount. A numeric field, not text: the server's Liquid engine does not turn a string into a number. A negative amount starts with «мінус» / «минус» / «minus».
words_currency yes An ISO 4217 code, any case (UAH, usd).
words_lang no uk (default), ru, en or de. Any other value prints [common-words: unknown language xx] instead of silently writing another language.
words_cap no true starts the text with a capital letter (One thousand ...). Liquid's own capitalize lowercases the rest of the text, so use this.

The snippet prints the text and nothing else, so it can sit inside a paragraph or a table cell: <p>Total: {% include 'common-words.money' %}</p>.

Where the values come from

  • Amount and currency are fields of the document you print. Use their column codes.
  • Language is whatever your document knows: a fixed word ('de'), a dropdown on the document, a setting. A dropdown prints as its label ("Deutsch"), not its code, so read the code from _raw: {% assign words_lang = _raw.lang %}.
  • A reference column (a currency picked from a list) prints as its display text. That is the code only if the referenced entity's toString is the code; otherwise keep the code in a plain column of the document.

One fixed language

When a form is always in one language, include that snippet directly and skip words_lang:

{% include 'common-words.money_uk' %}

money_uk, money_ru, money_en and money_de take the same words_amount, words_currency and words_cap.

A quantity in words

For a count of things rather than money: «двадцять одна штука», «twenty-one pieces», «einundzwanzig Stück».

{% assign words_number = qty %}
{% assign words_unit = 'штука|штуки|штук' %}
{% assign words_gender = 'f' %}
{% assign words_lang = 'uk' %}
{% include 'common-words.quantity' %}
Input Required Meaning
words_number yes The quantity, a numeric field. A fraction is rounded half up to a whole number; a negative one starts with «мінус» / «минус» / «minus».
words_unit no The unit's forms joined by |: three for Ukrainian and Russian (1, 2–4, 5+), two for English and German (1, other). One form is used for every number. Without it only the number is written.
words_gender no m (default), f or n: «один / одна / одне», «один / одна / одно», «ein / eine / ein». English ignores it.
words_lang, words_cap no As for money.
words_minor, words_minor_digits, words_minor_gender no Ukrainian and Russian. The fraction in words with its own unit, as 1C's ЧислоПрописью: see below.
words_decimal, words_unit_fraction no Ukrainian and Russian. The number as a decimal fraction in words: see below.
Quantity Language Result
21, штука|штуки|штук, f uk двадцять одна штука
2, кілограм|кілограми|кілограмів, m uk два кілограми
21, штука|штуки|штук, f ru двадцать одна штука
21, piece|pieces en twenty-one pieces
21, Stück de einundzwanzig Stück

quantity_uk, quantity_ru, quantity_en and quantity_de can be included directly, like the money ones. A thousand is always feminine in Ukrainian and Russian («дві тисячі», «две тысячи»), whatever words_gender says.

A fraction with its own unit (Ukrainian, Russian)

A weight is written as 1C's ЧислоПрописью(weight, , "кг.,кг.,кг.,м,г.,г.,г.,м,3") writes it: the whole number with its unit, then the fraction in words with its own:

{% assign words_number = weight %}
{% assign words_unit = 'кг.' %}
{% assign words_minor = 'г.' %}
{% assign words_minor_digits = 3 %}
{% assign words_cap = true %}
{% include 'common-words.quantity_ru' %}
Input Meaning
words_minor The fraction's unit, forms as for words_unit: 'г.', 'грамм|грамма|граммов'.
words_minor_digits 1 to 6: the fraction is rounded half up to that many digits and written in words. Without it the number is rounded to a whole and words_minor is ignored.
words_minor_gender The fraction unit's gender, as words_gender.
Quantity Result
1250.5, кг. / г., 3, cap Одна тысяча двести пятьдесят кг. пятьсот г.
12, кг. / г., 3 двенадцать кг. ноль г.
2.002, килограмм|… / грамм|…, 3 два килограмма два грамма

A zero fraction is written («ноль г.»), as 1C does. A fraction that rounds up to a whole carries: 0.9996 with 3 digits is «один кг. ноль г.». quantity_uk takes the same inputs: «одна тисяча двісті п'ятдесят кг п'ятсот г».

A decimal fraction (Ukrainian, Russian)

A weight in tonnes on a consignment note, «масою брутто, т (словами)», is a decimal fraction in words:

{% assign words_number = gross_t %}
{% assign words_unit = 'тонна|тонни|тонн' %}
{% assign words_gender = 'f' %}
{% assign words_decimal = true %}
{% include 'common-words.quantity_uk' %}
Input Meaning
words_decimal true: up to three digits, rounded half up, trailing zeros dropped. The whole part reads «ціла / цілих» («целая / целых»), the fraction «десята / сота / тисячна» («десятая / сотая / тысячная»), both feminine. A whole number is written as without it. Wins over words_minor.
words_unit_fraction The unit after a fraction, which takes the genitive singular. By default the 2–4 form of words_unit, right for «тонни», «килограмма»; a Ukrainian masculine unit needs it: 'кілограма'.
Quantity Language Result
21.12, тонна|тонни|тонн, f uk двадцять одна ціла дванадцять сотих тонни
0.345 uk нуль цілих триста сорок п'ять тисячних
1.001 uk одна ціла одна тисячна
3, тонна|тонни|тонн, f uk три тонни
2.5, килограмм|килограмма|килограммов ru две целых пять десятых килограмма

The text follows the grammar, not 1C's own: 1C writes 1.001 as «одна ціла один тисячна».

What it does

  • Minor units are written as two digits with their name («56 копійок», «56 cents», «56 Cent»). A currency with no minor unit (JPY) has none, and the amount is rounded half up to a whole number: 1234.56 JPY is «one thousand two hundred thirty-five yen».
  • Rounding is half up to the minor unit, on the decimal value: 960.015 is «… 02 копійки» in print and in the preview alike, although 960.015 is 960.01499… as a binary float in the browser.
  • Zero is spelled («нуль гривень 00 копійок», «ноль рублей 00 копеек», «zero ...», «null ...»).
  • Grammar follows each language: Ukrainian picks the singular, the 2–4 form or the plural by the last digits and the noun's gender («одна гривня», «дві гривні», «п'ять гривень», «дві тисячі»), and Russian the same way («один рубль», «два рубля», «пять рублей», «две тысячи»); English pluralises except for 1; German writes below a million as one word, uses «eine Million», and says «ein Euro» / «eine Hrywnja» for 1.
  • Up to 999 trillion. With a fraction, exact up to 100 trillion: above that the server's modulo loses the fraction.
  • A currency the module does not list prints the number and its code, minor units in digits: «three SEK 00».

Currencies

UAH, USD, EUR, GBP, PLN, CHF, CAD, AUD, JPY, RUB.

Add a currency

Each language file starts with a case on the currency code. Add a branch to each of print_templates/money_uk.html, money_en.html and money_de.html:

{%- when 'CZK' -%}
	{%- assign w_unit = 'koruna|koruny|korun' -%}
	{%- assign w_minor = 'halíř|haléře|haléřů' -%}
  • w_unit / w_minor are the noun forms joined by |. Ukrainian takes three (one / few / many: 1, 2–4, 5+), English and German two (one / other). A noun that never changes takes one form («євро», «Euro»).
  • w_fem = true (Ukrainian) or w_gender = 'f' / 'n' (German) when the unit is feminine / neuter: it decides «одна» / «eine» and «ein».
  • w_dec = 0 when the currency has no minor unit.
  • Leave w_minor out when there is no minor-unit word to print.

Bump the module version in manifest.json and add a changelog/{version}.md. Tenants get the new text on the next module upgrade.

Add a language

  1. Copy print_templates/money_en.html (two noun forms) or money_uk.html (three) to money_xx.html and rewrite the number words, the group assembly and the currency case for that language. The skeleton (splitting the amount into whole and minor units, the sign, the loop over the thousands groups, the capital letter) stays; the grammar is what changes.
  2. Do the same for quantity_xx.html, from quantity_en.html or quantity_uk.html.
  3. Declare both in ui/print_templates.json as a snippet with "file": "money_xx.html" / "quantity_xx.html".
  4. Add a when 'xx' line to print_templates/money.html and quantity.html.
  5. Add cases for it to clients/packages/data-ui/test/common-words.cases.json (lang, v, cur, expected) and common-words.quantity-cases.json (lang, v, unit, gender, expected) and run both test suites below. Check every expected against the language's grammar by hand: a wrong value in the file is a wrong value in both engines.

Write snippets for both engines

A snippet runs in two Liquid engines: Scriban on the server (print) and LiquidJS in the browser (preview and print from a card). Output must be identical, so:

  • No floor on the amount. Scriban's floor goes through a double and rounds a big amount up. Split with modulo, snap the whole part with round and take the fraction again by subtraction; LiquidJS 10.30 computes modulo as ((v % 1) + 1) % 1, so 0.44 | modulo: 1 is 0.43999999999999995. Round the fraction on its digits, not by arithmetic. Take the number's text (append: '', a comma read as a point, 5e-7 expanded) and round half up on the digit after the last one kept: a double's text is the shortest decimal that stands for it, so 960.015 (960.01499… as a double) reads «015» and rounds to 02, 1000000000.0049999 reads «0049999» and rounds to 00, and the server's decimals print exactly. No correction for float noise, since none is added — any epsilon that rescues a tie also lifts a value just below one (see the top of any money_xx.html).
  • No number from split or slice. Scriban keeps it a string and "1000" | plus: 0 concatenates. Branch with case / if, or use forloop and (0..n) ranges.
  • No {%- comment -%} with trim dashes. Scriban prints the comment. Use {% comment %} ... {% endcomment -%}.
  • No parentheses in conditions; Liquid has none. Use nested if.
  • Trim whitespace with {%- ... -%} so the snippet prints only the text.

Tests

The same case list runs against both engines:

# server: Scriban
cd server && dotnet test tests/dForge.Api.Tests --filter "FullyQualifiedName~CommonWords"

# client: LiquidJS
cd clients/packages/data-ui && pnpm exec vitest run src/lib/print/common-words.test.ts

The server run also installs the module into a fresh tenant and checks that every stored snippet is the file shipped here.

Common words
Try it
/ explore more

Browse the full
module catalog.

Every module is metadata — install it in one click, then change anything.