Skip to content

[String] Deprecated the Inflector docs #13670

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
60 changes: 4 additions & 56 deletions components/inflector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,8 @@
The Inflector Component
=======================

The Inflector component converts English words between their singular and
plural forms.
.. deprecated:: 5.1

Installation
------------

.. code-block:: terminal

$ composer require symfony/inflector

.. include:: /components/require_autoload.rst.inc

When you May Need an Inflector
------------------------------

In some scenarios such as code generation and code introspection, it's usually
required to convert words from/to singular/plural. For example, if you need to
know which property is associated with an *adder* method, you must convert from
plural to singular (``addStories()`` method -> ``$story`` property).

Although most human languages define simple pluralization rules, they also
define lots of exceptions. For example, the general rule in English is to add an
``s`` at the end of the word (``book`` -> ``books``) but there are lots of
exceptions even for common words (``woman`` -> ``women``, ``life`` -> ``lives``,
``news`` -> ``news``, ``radius`` -> ``radii``, etc.)

This component abstracts all those pluralization rules so you can convert
from/to singular/plural with confidence. However, due to the complexity of the
human languages, this component only provides support for the English language.

Usage
-----

The Inflector component provides two static methods to convert from/to
singular/plural::

use Symfony\Component\Inflector\Inflector;

Inflector::singularize('alumni'); // 'alumnus'
Inflector::singularize('knives'); // 'knife'
Inflector::singularize('mice'); // 'mouse'

Inflector::pluralize('grandchild'); // 'grandchildren'
Inflector::pluralize('news'); // 'news'
Inflector::pluralize('bacterium'); // 'bacteria'

Sometimes it's not possible to determine a unique singular/plural form for the
given word. In those cases, the methods return an array with all the possible
forms::

use Symfony\Component\Inflector\Inflector;

Inflector::singularize('indices'); // ['index', 'indix', 'indice']
Inflector::singularize('leaves'); // ['leaf', 'leave', 'leaff']

Inflector::pluralize('matrix'); // ['matricies', 'matrixes']
Inflector::pluralize('person'); // ['persons', 'people']
The Inflector component was deprecated in Symfony 5.1 and its code was moved
into the :doc:`String </components/string>` component.
:ref:`Read the new Inflector docs <string-inflector>`.
38 changes: 38 additions & 0 deletions components/string.rst
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,44 @@ the injected slugger is the same as the request locale::
}
}

.. _string-inflector:

Inflector
---------

..versionadded:: 5.1

The inflector feature was introduced in Symfony 5.1.

In some scenarios such as code generation and code introspection, you need to
convert words from/to singular/plural. For example, to know the property
associated with an *adder* method, you must convert from plural
(``addStories()`` method) to singular (``$story`` property).

Most human languages have simple pluralization rules, but at the same time they
define lots of exceptions. For example, the general rule in English is to add an
``s`` at the end of the word (``book`` -> ``books``) but there are lots of
exceptions even for common words (``woman`` -> ``women``, ``life`` -> ``lives``,
``news`` -> ``news``, ``radius`` -> ``radii``, etc.)

This component provides an :class:`Symfony\\Component\\String\\Inflector\\EnglishInflector`
class to convert English words from/to singular/plural with confidence::

use Symfony\Component\String\Inflector\EnglishInflector;

$inflector = new EnglishInflector();

$result = $inflector->singularize('teeth'); // ['tooth']
$result = $inflector->singularize('radii'); // ['radius']
$result = $inflector->singularize('leaves'); // ['leaf', 'leave', 'leaff']

$result = $inflector->pluralize('bacterium'); // ['bacteria']
$result = $inflector->pluralize('news'); // ['news']
$result = $inflector->pluralize('person'); // ['persons', 'people']

The value returned by both methods is always an array because sometimes it's not
possible to determine a unique singular/plural form for the given word.

.. _`ASCII`: https://en.wikipedia.org/wiki/ASCII
.. _`Unicode`: https://en.wikipedia.org/wiki/Unicode
.. _`Code points`: https://en.wikipedia.org/wiki/Code_point
Expand Down