CoolCMS API

DocumentLocale
in package

FinalYes

Language and format for the customer. Order e-mails and invoices are rendered not by who generates them (admin in Czech, cron without a language) but by the order:

  • texts (NEON translations, translator locale) follow the language of the order/invoice,
  • numbers and dates follow the localization of the order/invoice (cms_system_localizations: separators via PriceFormat, short_date_format).

Both entities arrive as ?object (Front/Admin/Api descendants, lazy proxies), hence method_exists and tolerant fallbacks: a missing value means Czech and the d.m.Y format, the behavior before language versions existed.

Table of Contents

Constants

DEFAULT_DATE_FORMAT  : string = 'd.m.Y'
DEFAULT_LOCALE  : string = 'cs_CZ'
DEFAULT_UNIT_CODE  : string = 'ks'
Unit code of an item without a unit (`cms_system_units.code`).
ALIAS_TO_LOCALE  : array<string|int, mixed> = ['cs' => 'cs_CZ', 'en' => 'en_US', 'sk' => 'sk_...
Language alias to the locale under which the NEON sources are registered (see TranslatorInitTrait).
TAX_NOTE_KEY_PREFIX  : string = '//document.invoicer.tax.note.'
Absolute message ID of VAT notes (`invoicer.tax.note.<CODE>[.<status>]`).
TAX_TITLE_KEY_PREFIX  : string = '//document.invoicer.tax.title.'
Absolute message ID of document titles (`invoicer.tax.title.<TYPE>.<CODE>[.<status>]`).
UNIT_KEY_PREFIX  : string = '//document.invoicer.units.'
Absolute message ID of document texts (app/Locale/invoicer/<locale>/document.*.neon).

Methods

dateTimeFormat()  : string
Date and time (dispatch): short date format of the localization + `H:i` (the customer does not need seconds).
formatNumber()  : string
Decimal number for document text (quantity, fee) with separators of the localization and currency.
shortDateFormat()  : string
Short date format of the localization (`short_date_format`); empty or missing gives `d.m.Y`.
taxNote()  : string|null
VAT note in the document language and, below it, in Czech (Czech is recommended, the default is bilingual). `$noteKey` is the engine key `tax.note.<CODE>[.<status>]` (neon `invoicer/<locale>/document.*.neon`); `null` means the code has no note (domestic). A missing translation gives `null`; a bare key never reaches the document.
taxTitle()  : string|null
Document title by document type x treatment code x seller status. Keys `tax.title.<TYPE>.<CODE>.<status>`, then `tax.title.<TYPE>.<CODE>`, then `tax.title.<TYPE>.default` (neon `invoicer/<locale>/document.*.neon`). The whole chain is tried in the document language first and only then in Czech: an English document must not get a Czech title just because a more specific English key is missing.
translate()  : string
Text in the document language. A missing translation (a translator with `returnOriginalMessage` returns the key) must not end up on the document as "//document...", so it falls back to Czech.
translatorLocale()  : string
Translator locale. The language takes precedence (it determines texts), the localization is a fallback for a document without a language; unknown values fall back to Czech, otherwise the translator would return bare keys.
unit()  : string
Unit abbreviation in the document language by unit code (`ks` gives `pcs` in English). The order carries the catalog code; an unknown code (or free text) is returned unchanged, an empty one means the default unit.
read()  : mixed

Constants

DEFAULT_UNIT_CODE

Unit code of an item without a unit (`cms_system_units.code`).

public string DEFAULT_UNIT_CODE = 'ks'

ALIAS_TO_LOCALE

Language alias to the locale under which the NEON sources are registered (see TranslatorInitTrait).

private array<string|int, mixed> ALIAS_TO_LOCALE = ['cs' => 'cs_CZ', 'en' => 'en_US', 'sk' => 'sk_SK']

TAX_NOTE_KEY_PREFIX

Absolute message ID of VAT notes (`invoicer.tax.note.<CODE>[.<status>]`).

private string TAX_NOTE_KEY_PREFIX = '//document.invoicer.tax.note.'

TAX_TITLE_KEY_PREFIX

Absolute message ID of document titles (`invoicer.tax.title.<TYPE>.<CODE>[.<status>]`).

private string TAX_TITLE_KEY_PREFIX = '//document.invoicer.tax.title.'

UNIT_KEY_PREFIX

Absolute message ID of document texts (app/Locale/invoicer/<locale>/document.*.neon).

private string UNIT_KEY_PREFIX = '//document.invoicer.units.'

Methods

dateTimeFormat()

Date and time (dispatch): short date format of the localization + `H:i` (the customer does not need seconds).

public static dateTimeFormat(object|null $localization) : string
Parameters
$localization : object|null
Return values
string

formatNumber()

Decimal number for document text (quantity, fee) with separators of the localization and currency.

public static formatNumber(float $value, int $scale, object|null $currency, object|null $localization[, bool $trimZeros = true ][, bool $groupThousands = true ]) : string

A whole number is printed without decimals, otherwise with $scale places without trailing zeros ($trimZeros) or a fixed number (money). $groupThousands = false omits the thousand separator (quantities on documents have always been printed that way: "1000", not "1.000").

Parameters
$value : float
$scale : int
$currency : object|null
$localization : object|null
$trimZeros : bool = true
$groupThousands : bool = true
Return values
string

shortDateFormat()

Short date format of the localization (`short_date_format`); empty or missing gives `d.m.Y`.

public static shortDateFormat(object|null $localization) : string
Parameters
$localization : object|null
Return values
string

taxNote()

VAT note in the document language and, below it, in Czech (Czech is recommended, the default is bilingual). `$noteKey` is the engine key `tax.note.<CODE>[.<status>]` (neon `invoicer/<locale>/document.*.neon`); `null` means the code has no note (domestic). A missing translation gives `null`; a bare key never reaches the document.

public static taxNote(Translator $translator, string|null $noteKey, string $locale) : string|null
Parameters
$translator : Translator
$noteKey : string|null
$locale : string
Return values
string|null

taxTitle()

Document title by document type x treatment code x seller status. Keys `tax.title.<TYPE>.<CODE>.<status>`, then `tax.title.<TYPE>.<CODE>`, then `tax.title.<TYPE>.default` (neon `invoicer/<locale>/document.*.neon`). The whole chain is tried in the document language first and only then in Czech: an English document must not get a Czech title just because a more specific English key is missing.

public static taxTitle(Translator $translator, string|null $invoiceTypeKey, string|null $taxTreatment, string|null $sellerStatus, string $locale) : string|null

null means the document type has no title (the template keeps its heading).

Parameters
$translator : Translator
$invoiceTypeKey : string|null
$taxTreatment : string|null
$sellerStatus : string|null
$locale : string
Return values
string|null

translate()

Text in the document language. A missing translation (a translator with `returnOriginalMessage` returns the key) must not end up on the document as "//document...", so it falls back to Czech.

public static translate(Translator $translator, string $key, string $locale[, array<string, string> $params = [] ]) : string
Parameters
$translator : Translator
$key : string
$locale : string
$params : array<string, string> = []
Return values
string

translatorLocale()

Translator locale. The language takes precedence (it determines texts), the localization is a fallback for a document without a language; unknown values fall back to Czech, otherwise the translator would return bare keys.

public static translatorLocale(object|null $language[, object|null $localization = null ]) : string
Parameters
$language : object|null
$localization : object|null = null
Return values
string

unit()

Unit abbreviation in the document language by unit code (`ks` gives `pcs` in English). The order carries the catalog code; an unknown code (or free text) is returned unchanged, an empty one means the default unit.

public static unit(Translator $translator, string|null $code, string $locale) : string
Parameters
$translator : Translator
$code : string|null
$locale : string
Return values
string

read()

private static read(object|null $source, string $getter) : mixed
Parameters
$source : object|null
$getter : string
On this page

Search results