Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

14
vendor/twig/extensions/doc/array.rst vendored Normal file
View File

@@ -0,0 +1,14 @@
The Array Extension
===================
The Array extensions provides the following filters:
* ``shuffle``
Installation
------------
First, :ref:`install the Extensions library<extensions-install>`. Next, add
the extension to Twig::
$twig->addExtension(new Twig_Extensions_Extension_Array());

41
vendor/twig/extensions/doc/date.rst vendored Normal file
View File

@@ -0,0 +1,41 @@
The Date Extension
===================
The *Date* extension provides the ``time_diff`` filter.
You need to register this extension before using the ``time_diff`` filter::
$twig->addExtension(new Twig_Extensions_Extension_Date());
``time_diff``
-------------
Use the ``time_diff`` filter to render the difference between a date and now.
.. code-block:: jinja
{{ post.published_at|time_diff }}
The example above will output a string like ``4 seconds ago`` or ``in 1 month``,
depending on the filtered date.
.. note::
Internally, Twig uses the PHP ``DateTime::diff()`` method for calculating the
difference between dates, this means that PHP 5.3+ is required.
Arguments
~~~~~~~~~
* ``date``: The date for calculate the difference from now. Can be a string
or a DateTime instance.
* ``now``: The date that should be used as now. Can be a string or
a DateTime instance. Do not set this argument to use current date.
Translation
~~~~~~~~~~~
To get a translatable output, give a ``Symfony\Component\Translation\TranslatorInterface``
as constructor argument. The returned string is formatted as ``diff.ago.XXX``
or ``diff.in.XXX`` where ``XXX`` can be any valid unit: second, minute, hour, day, month, year.

191
vendor/twig/extensions/doc/i18n.rst vendored Normal file
View File

@@ -0,0 +1,191 @@
The i18n Extension
==================
Configuration
-------------
The ``i18n`` extension adds `gettext`_ support to Twig. It defines one tag,
``trans``.
To use it, first, :ref:`install the Extensions library<extensions-install>`.
You need to register this extension before using the ``trans`` block::
$twig->addExtension(new Twig_Extensions_Extension_I18n());
Note that you must configure the ``gettext`` extension before rendering any
internationalized template. Here is a simple configuration example from the
PHP `documentation`_::
// Set language to French
putenv('LC_ALL=fr_FR');
setlocale(LC_ALL, 'fr_FR');
// Specify the location of the translation tables
bindtextdomain('myAppPhp', 'includes/locale');
bind_textdomain_codeset('myAppPhp', 'UTF-8');
// Choose domain
textdomain('myAppPhp');
.. caution::
The ``i18n`` extension only works if the PHP `gettext`_ extension is
enabled.
Usage
-----
Use the ``trans`` block to mark parts in the template as translatable:
.. code-block:: jinja
{% trans "Hello World!" %}
{% trans string_var %}
{% trans %}
Hello World!
{% endtrans %}
In a translatable string, you can embed variables:
.. code-block:: jinja
{% trans %}
Hello {{ name }}!
{% endtrans %}
During the gettext lookup these placeholders are converted. ``{{ name }}`` becomes ``%name%`` so the gettext ``msgid`` for this string would be ``Hello %name%!``.
.. note::
``{% trans "Hello {{ name }}!" %}`` is not a valid statement.
If you need to apply filters to the variables, you first need to assign the
result to a variable:
.. code-block:: jinja
{% set name = name|capitalize %}
{% trans %}
Hello {{ name }}!
{% endtrans %}
To pluralize a translatable string, use the ``plural`` block:
.. code-block:: jinja
{% trans %}
Hey {{ name }}, I have one apple.
{% plural apple_count %}
Hey {{ name }}, I have {{ count }} apples.
{% endtrans %}
The ``plural`` tag should provide the ``count`` used to select the right
string. Within the translatable string, the special ``count`` variable always
contain the count value (here the value of ``apple_count``).
To add notes for translators, use the ``notes`` block:
.. code-block:: jinja
{% trans %}
Hey {{ name }}, I have one apple.
{% plural apple_count %}
Hey {{ name }}, I have {{ count }} apples.
{% notes %}
This is shown in the user menu. This string should be shorter than 30 chars
{% endtrans %}
You can use ``notes`` with or without ``plural``. Once you get your templates compiled you should
configure the ``gettext`` parser to get something like this: ``xgettext --add-comments=notes``
Within an expression or in a tag, you can use the ``trans`` filter to translate
simple strings or variables:
.. code-block:: jinja
{{ var|default(default_value|trans) }}
Complex Translations within an Expression or Tag
------------------------------------------------
Translations can be done with both the ``trans`` tag and the ``trans`` filter.
The filter is less powerful as it only works for simple variables or strings.
For more complex scenario, like pluralization, you can use a two-step
strategy:
.. code-block:: jinja
{# assign the translation to a temporary variable #}
{% set default_value %}
{% trans %}
Hey {{ name }}, I have one apple.
{% plural apple_count %}
Hey {{ name }}, I have {{ count }} apples.
{% endtrans %}
{% endset %}
{# use the temporary variable within an expression #}
{{ var|default(default_value|trans) }}
Extracting Template Strings
---------------------------
If you use the Twig I18n extension, you will probably need to extract the
template strings at some point.
Using Poedit 2
~~~~~~~~~~~~~~
Poedit 2 has native support for extracting from Twig files and no extra
setup is necessary (Pro version).
Using ``xgettext`` or Poedit 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unfortunately, the ``xgettext`` utility does not understand Twig templates
natively and neither do tools based on it such as free versions of Poedit.
But there is a simple workaround: as Twig converts templates to
PHP files, you can use ``xgettext`` on the template cache instead.
Create a script that forces the generation of the cache for all your
templates. Here is a simple example to get you started::
$tplDir = dirname(__FILE__).'/templates';
$tmpDir = '/tmp/cache/';
$loader = new Twig_Loader_Filesystem($tplDir);
// force auto-reload to always have the latest version of the template
$twig = new Twig_Environment($loader, array(
'cache' => $tmpDir,
'auto_reload' => true
));
$twig->addExtension(new Twig_Extensions_Extension_I18n());
// configure Twig the way you want
// iterate over all your templates
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tplDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file)
{
// force compilation
if ($file->isFile()) {
$twig->loadTemplate(str_replace($tplDir.'/', '', $file));
}
}
Use the standard ``xgettext`` utility as you would have done with plain PHP
code:
.. code-block:: text
xgettext --default-domain=messages -p ./locale --from-code=UTF-8 -n --omit-header -L PHP /tmp/cache/*.php
Another workaround is to use `Twig Gettext Extractor`_ and extract the template
strings right from `Poedit`_.
.. _`gettext`: http://www.php.net/gettext
.. _`documentation`: http://fr.php.net/manual/en/function.gettext.php
.. _`Twig Gettext Extractor`: https://github.com/umpirsky/Twig-Gettext-Extractor
.. _`Poedit`: http://www.poedit.net/

39
vendor/twig/extensions/doc/index.rst vendored Normal file
View File

@@ -0,0 +1,39 @@
Twig Extensions
===============
.. toctree::
:hidden:
text
i18n
intl
array
date
The Twig Extensions is a library that provides several useful extensions
for Twig. You can find it's code at `GitHub.com/twigphp/Twig-extensions`_.
.. _extensions-install:
Installation
------------
This library can be installed via Composer running the following from the
command line:
.. code-block:: bash
composer require twig/extensions
* :doc:`Text <text>`: Provides useful filters for text manipulation;
* :doc:`I18n <i18n>`: Adds internationalization support via the ``gettext``
library;
* :doc:`Intl <intl>`: Adds a filter for localization of ``DateTime`` objects, numbers and currency;
* :doc:`Array <array>`: Provides useful filters for array manipulation;
* :doc:`Date <date>`: Adds a filter for rendering the difference between dates.
.. _`GitHub.com/twigphp/Twig-extensions`: https://github.com/twigphp/Twig-extensions

160
vendor/twig/extensions/doc/intl.rst vendored Normal file
View File

@@ -0,0 +1,160 @@
The Intl Extension
==================
The *Intl* extensions provides the ``localizeddate``, ``localizednumber`` and ``localizedcurrency`` filters.
Installation
------------
First, :ref:`install the Extensions library<extensions-install>`. Next, add
the extension to Twig::
$twig->addExtension(new Twig_Extensions_Extension_Intl());
``localizeddate``
-----------------
Use the ``localizeddate`` filter to format dates into a localized string
representating the date.
.. code-block:: jinja
{{ post.published_at|localizeddate('medium', 'none', locale) }}
The ``localizeddate`` filter accepts strings (it must be in a format supported
by the `strtotime`_ function), `DateTime`_ instances, or `Unix timestamps`_.
.. note::
Internally, Twig uses the PHP `IntlDateFormatter::create()`_ function for
the date.
Arguments
~~~~~~~~~
* ``date_format``: The date format. Choose one of these formats:
* 'none': `IntlDateFormatter::NONE`_
* 'short': `IntlDateFormatter::SHORT`_
* 'medium': `IntlDateFormatter::MEDIUM`_
* 'long': `IntlDateFormatter::LONG`_
* 'full': `IntlDateFormatter::FULL`_
* ``time_format``: The time format. Same formats possible as above.
* ``locale``: The locale used for the format. If ``NULL`` is given, Twig will
use ``Locale::getDefault()``
* ``timezone``: The date timezone
* ``format``: Optional pattern to use when formatting or parsing. Possible
patterns are documented in the `ICU user guide`_.
* ``calendar``: Calendar to use for formatting. The default value is 'gregorian',
which corresponds to IntlDateFormatter::GREGORIAN. Choose one of these formats:
* 'gregorian': `IntlDateFormatter::GREGORIAN`_
* 'traditional': `IntlDateFormatter::TRADITIONAL`_
For the following calendars should use 'traditional':
* Japanese
* Buddhist
* Chinese
* Persian
* Indian
* Islamic
* Hebrew
* Coptic
* Ethiopic
Also for non-Gregorian calendars need to be specified in locale.
Examples might include locale="fa_IR@calendar=PERSIAN".
``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 number 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
.. _`IntlDateFormatter::GREGORIAN`: http://php.net/IntlDateFormatter#intldateformatter.constants.gregorian
.. _`IntlDateFormatter::TRADITIONAL`: http://php.net/IntlDateFormatter#intldateformatter.constants.traditional
.. _`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

76
vendor/twig/extensions/doc/text.rst vendored Normal file
View File

@@ -0,0 +1,76 @@
The Text Extension
==================
The Text extension provides the following filters:
* ``truncate``
* ``wordwrap``
Installation
------------
First, :ref:`install the Extensions library<extensions-install>`. Next, add
the extension to Twig::
$twig->addExtension(new Twig_Extensions_Extension_Text());
Wrapping Words
--------------
Use the ``wordwrap`` filter to split your text in lines with equal length.
.. code-block:: jinja
{{ "Lorem ipsum dolor sit amet, consectetur adipiscing"|wordwrap(10) }}
This example would print::
Lorem ipsu
m dolor si
t amet, co
nsectetur
adipiscing
The default separator is "\\n", but you can easily change that by providing one:
.. code-block:: jinja
{{ "Lorem ipsum dolor sit amet, consectetur adipiscing"|wordwrap(10, "zz\n") }}
This would result in::
Lorem ipsuzz
m dolor sizz
t amet, cozz
nsectetur zz
adipiscing
Truncating Text
---------------
Use the ``truncate`` filter to cut off a string after limit is reached
.. code-block:: jinja
{{ "Hello World!"|truncate(5) }}
The example would output ``Hello...``, as ``...`` is the default separator.
You can also tell truncate to preserve whole words by setting the second
parameter to ``true``. If the last Word is on the the separator, truncate
will print out the whole Word.
.. code-block:: jinja
{{ "Hello World!"|truncate(7, true) }}
Here ``Hello World!`` would be printed.
If you want to change the separator, just set the third parameter to
your desired separator.
.. code-block:: jinja
{{ "Hello World!"|truncate(7, false, "??") }}
This example would print ``Hello W??``.