Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd2ccdcf

Browse files
committed
minor#9248 [Validator] Add docs for "canonicalize" option atLocale validation constraint (phansys, javiereguiluz)
This PR was merged into the master branch.Discussion----------[Validator] Add docs for "canonicalize" option at `Locale` validation constraintRelated tosymfony/symfony#22353,symfony/symfony#26075.Closes#7660.Commits-------14f10bc Final changes4c28e1f Minor changes0cc4ee8 Add docs for "canonicalize" option at `Locale` validation constraint
2 parents4e30af2 +14f10bc commitd2ccdcf

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 iseitherthetwo letter `ISO 639-1`_ *language*
7-
code (e.g. ``fr``), or the language code followed by an underscore (``_``),
8-
thenthe `ISO 3166-1 alpha-2`_ *country* code (e.g. ``fr_FR`` for
9-
French/France).
6+
The "value" for each locale isany ofthe`ICU format locale IDs`_. For example,
7+
the two letter `ISO 639-1`_ *language*code (e.g. ``fr``), or the language code
8+
followed by an underscore (``_``) andthe `ISO 3166-1 alpha-2`_ *country* code
9+
(e.g. ``fr_FR`` forFrench/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
<classname="App\Entity\User">
5963
<propertyname="locale">
60-
<constraintname="Locale" />
64+
<constraintname="Locale">
65+
<optionname="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+
112+
.. _`ICU format locale IDs`:http://userguide.icu-project.org/locale
93113
.. _`ISO 639-1`:https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
94114
.. _`ISO 3166-1 alpha-2`:https://en.wikipedia.org/wiki/ISO_3166-1#Current_codes

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp