Formatting money in twig templates - numbers

Are there any filters or something like that in twig template engine to format money or numbers?

The number_format filter has been included in the Twig core since the end of December 2011. The relevant commit is here.
Usage: number_format(decimals, decimalSeparator, thousandSeparator)
{{ total|number_format(2) }}
{{ total|number_format(0, '.') }}
{{ total|number_format(2, '.', ',') }}
Read more about it in the docs

The Twig Extensions library contains a number of useful extensions for Twig. With the release of version 1.2.0, a localizedcurrency filter has been added to the Intl extension. As the name suggests, this filter will format a number based on the current locale. It uses PHP's NumberFormatter class to do so.
Usage
This filter is very easy to use. The only required argument for the filter is the 3-letter ISO 4217 currency code. For instance, to display an amount of 27.99 in Euros, use the following line of code:
{{ price|localizedcurrency('EUR') }}
This will display different results depending on the locale:
€27.99 if the locale is set to en
27,99 € if the locale is set to fr
€ 27,99 if the locale is set to nl
Installation / setting the locale
Installation instructions for the Intl extension can be found in this seperate answer.

If you are using an older version of twig and you don't want to install any extensions you can use the format filter like this:
{{ "%.2f"|format(total) }}
Not very nice, but it works.
Basically format works like PHP's sprintf function

Use the format_currency
From version 2.12 format_currency filter was added. More information in the official documentation https://twig.symfony.com/doc/2.x/filters/format_currency.html

Related

Mongo locale variant meaning

Some mongoDB locales have variants: for instance Catalan has variant search and Spanish has variants search and traditional. What do those variants mean and what effect do they have on string comparisons? MongoDB documentation specifies which variants are available for each supported language (see this page from their maunal) but it does not specify what do they mean.
The collation data comes from CLDR - Unicode Common Locale Data Repository.
Downloading the common archive and looking for the ca locale (common/collation/ca.xml), it has the following notes. Standard variant:
<!-- standard collation &L<<ŀ=l·<<<Ŀ=L· is equivalent to root collation order
(except root uses prefix rules for the middle dot, rather than contractions)
references="Enciclopèdia Catalana: Diccionari de la llengua catalana ISBN 84-85194-46-2" -->
Search variant:
# Below are the rules specific to ca.
# Per Apple language group, these are modified from standard rules below
# to make L primary-different from L-dot for search.

$Date.Format on Silverstripe 4 Template

I have a date in the database with this format "YY-mm-dd". On the template I want it in this format: dd.mm.YY
Usually it would work with $date.Format('d.m.Y')
But not in Silverstripe 4. It converts from 2018-05-08 to 8.0.2018. Only the year is correct. Was there a change. I didn't find anything in the Documentation
Date formats in SS4 were changed from PHP date formatting to CLDR date formatting (changelog link):
Changed Format() method to use CLDR format strings, rather than PHP format string. E.g. d/m/Y H:i:s (php format) should be replaced with to dd/MM/y HH:mm:ss (CLDR format).
You can use this to achieve what you want:
$Date.Format('dd.MM.y')
The guide mentioned in the previous answer regarding date formatting has moved. The new location for CLDR date formatting as used by Silverstripe 4 can be found here:
https://unicode-org.github.io/icu/userguide/format_parse/datetime/#date-field-symbol-table

Change dashes to slashes in cakephp generated date selects

When cake generates the 3 select boxes for a 'type'=>'date' input is there a way to change the dashes in between each select to slashes instead? Just for visual customization. I realize I can do it with javascript but I'm trying to see if I can avoid it if possible.
Found this answer
Cakephp customizing the output of date input form helpers
'separator' => 'YOUR_SEPARATOR'

Internationalize date formatting in Go

I currently have the following markup in a Go template:
{{ .PublishedAt.Format " Jan 02, 2006" }}
I'd like to display it using this format, but in another language. Is this a feature built-in in Go? If not, what is the best practice to achieve this?

lang = 5 letters for Apple's Search API, am I missing something?

Apple's search API documents specify:
lang =
The language, English or Japanese, you want to use when returning search results. Specify the language using the five-letter codename. For example: en_us.
The default is en_us (English).
examples: en_us, ja_jp
However, I cannot find this 5 letter standard codename. Are they just expecting a ISO 639-1 Code concatenated with a 2 letter country code?
Has anybody ran into this issue before?
As you can see the document below, en_us, ja_jp is not a "example" but the supported values for lang parameter key.
https://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html
This means, currently this api supports only these two langeages.
Hope this helps.