Skip to content

Commit 432ed07

Browse files
committed
Add docs for "canonicalize" option at Locale validation constraint
1 parent 713718f commit 432ed07

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

reference/constraints/Locale.rst

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ Locale
33

44
Validates that a value is a valid locale.
55

6-
The "value" for each locale is either the two letter `ISO 639-1`_ *language*
7-
code (e.g. ``fr``), or the language code followed by an underscore (``_``),
8-
then the `ISO 3166-1 alpha-2`_ *country* code (e.g. ``fr_FR`` for
9-
French/France).
6+
The "value" for each locale is any of `ICU format locale IDs`. By instance the two
7+
letter `ISO 639-1`_ *language* code (e.g. ``fr``), or the language code followed
8+
by an underscore (``_``), then the `ISO 3166-1 alpha-2`_ *country* code (e.g. ``fr_FR``
9+
for French/France).
1010

1111
+----------------+------------------------------------------------------------------------+
1212
| Applies to | :ref:`property or method <validation-property-target>` |
1313
+----------------+------------------------------------------------------------------------+
1414
| Options | - `message`_ |
1515
| | - `payload`_ |
16+
| | - `canonicalize`_ |
1617
+----------------+------------------------------------------------------------------------+
1718
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Locale` |
1819
+----------------+------------------------------------------------------------------------+
@@ -34,7 +35,9 @@ Basic Usage
3435
class User
3536
{
3637
/**
37-
* @Assert\Locale()
38+
* @Assert\Locale(
39+
* canonicalize = true
40+
* )
3841
*/
3942
protected $locale;
4043
}
@@ -45,7 +48,8 @@ Basic Usage
4548
App\Entity\User:
4649
properties:
4750
locale:
48-
- Locale: ~
51+
- Locale:
52+
canonicalize: true
4953
5054
.. code-block:: xml
5155
@@ -57,7 +61,9 @@ Basic Usage
5761
5862
<class name="App\Entity\User">
5963
<property name="locale">
60-
<constraint name="Locale" />
64+
<constraint name="Locale">
65+
<option name="canonicalize">true</option>
66+
</constraint>
6167
</property>
6268
</class>
6369
</constraint-mapping>
@@ -74,7 +80,7 @@ Basic Usage
7480
{
7581
public static function loadValidatorMetadata(ClassMetadata $metadata)
7682
{
77-
$metadata->addPropertyConstraint('locale', new Assert\Locale());
83+
$metadata->addPropertyConstraint('locale', new Assert\Locale(array('canonicalize' => true)));
7884
}
7985
}
8086
@@ -90,5 +96,18 @@ This message is shown if the string is not a valid locale.
9096

9197
.. include:: /reference/constraints/_payload-option.rst.inc
9298

99+
canonicalize
100+
~~~~~~~~~~~~
101+
102+
**type**: ``boolean`` **default**: ``false``
103+
104+
.. versionadded:: 4.1
105+
Using this option with value `false` was deprecated in Symfony 4.1 and it will
106+
throw an exception in Symfony 5.0, use `true` instead.
107+
108+
If true, then the :phpmethod:`Locale::canonicalize` method will be applied to
109+
check the validity of the given locale.
110+
93111
.. _`ISO 639-1`: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
94112
.. _`ISO 3166-1 alpha-2`: https://en.wikipedia.org/wiki/ISO_3166-1#Current_codes
113+
.. _`ICU format locale IDs`: http://userguide.icu-project.org/locale#TOC-Canonicalization

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy