Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
Add documentation for localizednumber and localizedcurrency filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Michaël Perrin committed Jul 30, 2014
1 parent f6c4130 commit 76f532d
Showing 1 changed file with 85 additions and 10 deletions.
95 changes: 85 additions & 10 deletions doc/intl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,88 @@ Arguments
* ``format``: Optional pattern to use when formatting or parsing. Possible
patterns are documented in the `ICU user guide`_.

.. _`strtotime`: http://php.net/strtotime
.. _`DateTime`: http://php.net/DateTime
.. _`Unix timestamps`: http://en.wikipedia.org/wiki/Unix_time
.. _`IntlDateFormatter::create()`: http://php.net/manual/en/intldateformatter.create.php
.. _`IntlDateFormatter::NONE`: http://php.net/manual/en/class.intldateformatter.php#intldateformatter.constants.none
.. _`IntlDateFormatter::SHORT`: http://php.net/manual/en/class.intldateformatter.php#intldateformatter.constants.short
.. _`IntlDateFormatter::MEDIUM`: http://php.net/manual/en/class.intldateformatter.php#intldateformatter.constants.medium
.. _`IntlDateFormatter::LONG`: http://php.net/manual/en/class.intldateformatter.php#intldateformatter.constants.long
.. _`IntlDateFormatter::FULL`: http://php.net/manual/en/class.intldateformatter.php#intldateformatter.constants.full
.. _`ICU user guide`: http://userguide.icu-project.org/formatparse/datetime
``localizednumber``
-------------------

Use the ``localizednumber`` filter to format numbers into a localized string
representating the number.

.. code-block:: jinja
{{ product.quantity|localizednumber }}
.. note::

Internally, Twig uses the PHP `NumberFormatter::create()`_ function for
the number.

Arguments
~~~~~~~~~

* ``style``: Optional date format (default: 'decimal'). Choose one of these formats:

* 'decimal': `NumberFormatter::DECIMAL`_
* 'currency': `NumberFormatter::CURRENCY`_
* 'percent': `NumberFormatter::PERCENT`_
* 'scientific': `NumberFormatter::SCIENTIFIC`_
* 'spellout': `NumberFormatter::SPELLOUT`_
* 'ordinal': `NumberFormatter::ORDINAL`_
* 'duration': `NumberFormatter::DURATION`_

* ``type``: Optional formatting type to use (default: 'default'). Choose one of these types:

* 'default': `NumberFormatter::TYPE_DEFAULT`_
* 'int32': `NumberFormatter::TYPE_INT32`_
* 'int64': `NumberFormatter::TYPE_INT64`_
* 'double': `NumberFormatter::TYPE_DOUBLE`_
* 'currency': `NumberFormatter::TYPE_CURRENCY`_

* ``locale``: The locale used for the format. If ``NULL`` is given, Twig will
use ``Locale::getDefault()``

``localizedcurrency``
---------------------

Use the ``localizedcurrency`` filter to format a currency value into a localized string.

.. code-block:: jinja
{{ product.price|localizedcurrency('EUR') }}
.. note::

Internally, Twig uses the PHP `NumberFormatter::create()`_ function for
the number.

Arguments
~~~~~~~~~

* ``currency``: The 3-letter ISO 4217 currency code indicating the currency to use.

* ``locale``: The locale used for the format. If ``NULL`` is given, Twig will
use ``Locale::getDefault()``


.. _`strtotime`: http://php.net/strtotime
.. _`DateTime`: http://php.net/DateTime
.. _`Unix timestamps`: http://en.wikipedia.org/wiki/Unix_time
.. _`IntlDateFormatter::create()`: http://php.net/manual/en/intldateformatter.create.php
.. _`IntlDateFormatter::NONE`: http://php.net/manual/en/class.intldateformatter.php#intldateformatter.constants.none
.. _`IntlDateFormatter::SHORT`: http://php.net/manual/en/class.intldateformatter.php#intldateformatter.constants.short
.. _`IntlDateFormatter::MEDIUM`: http://php.net/manual/en/class.intldateformatter.php#intldateformatter.constants.medium
.. _`IntlDateFormatter::LONG`: http://php.net/manual/en/class.intldateformatter.php#intldateformatter.constants.long
.. _`IntlDateFormatter::FULL`: http://php.net/manual/en/class.intldateformatter.php#intldateformatter.constants.full
.. _`ICU user guide`: http://userguide.icu-project.org/formatparse/datetime
.. _`NumberFormatter::create()`: http://php.net/manual/en/numberformatter.create.php
.. _`NumberFormatter::DECIMAL`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.decimal
.. _`NumberFormatter::CURRENCY`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.currency
.. _`NumberFormatter::PERCENT`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.percent
.. _`NumberFormatter::SCIENTIFIC`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.scientific
.. _`NumberFormatter::SPELLOUT`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.spellout
.. _`NumberFormatter::ORDINAL`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.ordinal
.. _`NumberFormatter::DURATION`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.duration
.. _`NumberFormatter::TYPE_DEFAULT`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.type-default
.. _`NumberFormatter::TYPE_INT32`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.type-int32
.. _`NumberFormatter::TYPE_INT64`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.type-int64
.. _`NumberFormatter::TYPE_DOUBLE`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.type-double
.. _`NumberFormatter::TYPE_CURRENCY`: http://php.net/manual/en/class.numberformatter.php#numberformatter.constants.type-currency

0 comments on commit 76f532d

Please sign in to comment.