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

[Validator] Add docs for "canonicalize" option atLocale validation constraint#9248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
javiereguiluz merged 3 commits intosymfony:masterfromphansys:pr_26075
Feb 23, 2018
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletionsreference/constraints/Locale.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,16 +3,17 @@ Locale

Validates that a value is a valid locale.

The "value" for each locale iseitherthetwo letter `ISO 639-1`_ *language*
code (e.g. ``fr``), or the language code followed by an underscore (``_``),
thenthe `ISO 3166-1 alpha-2`_ *country* code (e.g. ``fr_FR`` for
French/France).
The "value" for each locale isany ofthe`ICU format locale IDs`_. For example,
the two letter `ISO 639-1`_ *language*code (e.g. ``fr``), or the language code
followed by an underscore (``_``) andthe `ISO 3166-1 alpha-2`_ *country* code
(e.g. ``fr_FR`` forFrench/France).

+----------------+------------------------------------------------------------------------+
| Applies to | :ref:`property or method <validation-property-target>` |
+----------------+------------------------------------------------------------------------+
| Options | - `message`_ |
| | - `payload`_ |
| | - `canonicalize`_ |
+----------------+------------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Locale` |
+----------------+------------------------------------------------------------------------+
Expand All@@ -34,7 +35,9 @@ Basic Usage
class User
{
/**
* @Assert\Locale()
* @Assert\Locale(
* canonicalize = true
* )
*/
protected $locale;
}
Expand All@@ -45,7 +48,8 @@ Basic Usage
App\Entity\User:
properties:
locale:
- Locale: ~
- Locale:
canonicalize: true

.. code-block:: xml

Expand All@@ -57,7 +61,9 @@ Basic Usage

<class name="App\Entity\User">
<property name="locale">
<constraint name="Locale" />
<constraint name="Locale">
<option name="canonicalize">true</option>
</constraint>
</property>
</class>
</constraint-mapping>
Expand All@@ -74,7 +80,7 @@ Basic Usage
{
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('locale', new Assert\Locale());
$metadata->addPropertyConstraint('locale', new Assert\Locale(array('canonicalize' => true)));
}
}

Expand All@@ -90,5 +96,19 @@ This message is shown if the string is not a valid locale.

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

canonicalize
~~~~~~~~~~~~

**type**: ``boolean`` **default**: ``false``

.. versionadded:: 4.1
Using this option with value ``false`` was deprecated in Symfony 4.1 and it
  will throw an exception in Symfony 5.0. Use ``true`` instead.

If true, the :phpmethod:`Locale::canonicalize` method will be applied before checking
the validity of the given locale (e.g. ``FR-fr.utf8`` is transformed into ``fr_FR``
).

.. _`ICU format locale IDs`: http://userguide.icu-project.org/locale
.. _`ISO 639-1`: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
.. _`ISO 3166-1 alpha-2`: https://en.wikipedia.org/wiki/ISO_3166-1#Current_codes

[8]ページ先頭

©2009-2025 Movatter.jp