10000 Add docs for "canonicalize" option at `Locale` validation constraint · symfony/symfony-docs@0cc4ee8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0cc4ee8

Browse files
committed
Add docs for "canonicalize" option at Locale validation constraint
1 parent 45ba13c commit 0cc4ee8

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

reference/constraints/Locale.rst

Lines changed: 28 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,19 @@ 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
106+
will throw an exception in Symfony 5.0, use `true` instead.
107+
108+
If true, the :phpmethod:`Locale::canonicalize` method will be applied before checking
109+
the validity of the given locale (e.g. ``FR-fr.utf8`` is transformed into ``fr_FR``
110+
).
111+
93112
.. _`ISO 639-1`: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
94113
.. _`ISO 3166-1 alpha-2`: https://en.wikipedia.org/wiki/ISO_3166-1#Current_codes
114+
.. _`ICU format locale IDs`: http://userguide.icu-project.org/locale#TOC-Canonicalization

0 commit comments

Comments
 (0)
0