Amounts in words and translit
Two text helpers of common() have a choice of how they work: common()->num2str() writes an amount in
words for invoices and receipts, common()->make_translit() writes Ukrainian or Russian text in Latin letters (it also makes
the URL names of _propose_url_from_name()). Existing sites keep the built-in tables (legacy); sites installed
from 2026-11-28 get the ICU spelling and the national translit table in their config/project_conf.php.
Amounts in words: num2str()
common()->num2str(1234.5, 'UAH', 'ua'); // одна тисяча двісті тридцять чотири гривні 50 копійок
common()->num2str(21, 'USD', 'en'); // twenty one dollars 0 cents
$PROJECT_CONF['common_num2string']['DRIVER'] | What spells the number |
|---|---|
legacy (default) | The word tables of yf_common_num2string (languages UA, EN;
currencies UAH, USD, EUR). |
intl (new sites) | ICU spellout of ext-intl for the number (the feminine forms where the currency needs them:
"одна гривня", "дві гривні"); the currency and cent words still come from the tables. Without ext-intl it falls back to
legacy and logs once. |
Options of the object (_class('common_num2string', 'classes/common/')): sign(true) adds "plus",
cent_number(false) writes the cents in words, cent_zero(false) leaves out zero cents. An amount may be a numeric
string, which keeps every digit (up to quadrillions).
$PROJECT_CONF['common_num2string']['DRIVER'] = 'intl';
Translit: make_translit()
common()->make_translit('Згода Щастя'); // legacy: Zgoda SHCHastya, uk_kmu2010: Zghoda Shchastia
$PROJECT_CONF['translit']['TABLE'] | Table |
|---|---|
legacy (default) | The built-in mixed Russian / Ukrainian table. |
uk_kmu2010 | The official Ukrainian romanisation (Cabinet of Ministers resolution 55 of 2010): є, ї, й, ю, я at the start of a word as ye, yi, y, yu, ya, "зг" as zgh, the apostrophe not written. |
ru_icao | Russian as in passports (ICAO Doc 9303). |
intl | The ICU BGN rules of the language (ext-intl); BGN keeps soft signs as apostrophes and marks a split letter pair with one (Z'hoda). |
national (new sites) | uk_kmu2010 or ru_icao by the site language; for other languages
the letters decide (і, ї, є, ґ mean Ukrainian). |
A word in capitals stays in capitals, a capitalised word gets one capital ("Shchastia"). A table is a PHP file returning
['pairs' => ['а' => 'a', ...], 'initial' => ['є' => 'ye', ...]] with lower case letters; put your own in a folder of
$PROJECT_CONF['translit']['TABLE_DIRS'] and name it in TABLE. A table file is PHP code that runs when it loads:
TABLE_DIRS is set in the site config only (it is not on the Settings page), and its folders must not be writable from the web. One call may name its table:
_class('translit', 'classes/common/')->make($text, 'ru_icao'). URL names of existing pages are stored, so a new table changes
only the names made from then on.