Skip to content

[9.x] Added Pluralizer::useLanguage documentation #7894

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 2 commits into from
Apr 22, 2022
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
8 changes: 4 additions & 4 deletions controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ When using a custom keyed implicit binding as a nested route parameter, Laravel
<a name="restful-localizing-resource-uris"></a>
### Localizing Resource URIs

By default, `Route::resource` will create resource URIs using English verbs. If you need to localize the `create` and `edit` action verbs, you may use the `Route::resourceVerbs` method. This may be done at the beginning of the `boot` method within your application's `App\Providers\RouteServiceProvider`:
By default, `Route::resource` will create resource URIs using English verbs and plural rules. If you need to localize the `create` and `edit` action verbs, you may use the `Route::resourceVerbs` method. This may be done at the beginning of the `boot` method within your application's `App\Providers\RouteServiceProvider`:

/**
* Define your route model bindings, pattern filters, etc.
Expand All @@ -343,11 +343,11 @@ By default, `Route::resource` will create resource URIs using English verbs. If
// ...
}

Once the verbs have been customized, a resource route registration such as `Route::resource('fotos', PhotoController::class)` will produce the following URIs:
Laravel's pluralizer supports [several different languages which you may configure based on your needs](/docs/{{version}}/localization#pluralization-language). Once the verbs and pluralization language have been customized, a resource route registration such as `Route::resource('publicacion', PublicacionController::class)` will produce the following URIs:

/fotos/crear
/publicacion/crear

/fotos/{foto}/editar
/publicacion/{publicaciones}/editar

<a name="restful-supplementing-resource-controllers"></a>
### Supplementing Resource Controllers
Expand Down
10 changes: 5 additions & 5 deletions helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@ The `Str::padRight` method wraps PHP's `str_pad` function, padding the right sid
<a name="method-str-plural"></a>
#### `Str::plural()` {.collection-method}

The `Str::plural` method converts a singular word string to its plural form. This function currently only supports the English language:
The `Str::plural` method converts a singular word string to its plural form. This function supports [any of the languages support by Laravel's pluralizer](/docs/{{version}}/localization#pluralization-language):

use Illuminate\Support\Str;

Expand All @@ -1610,7 +1610,7 @@ You may provide an integer as a second argument to the function to retrieve the
<a name="method-str-plural-studly"></a>
#### `Str::pluralStudly()` {.collection-method}

The `Str::pluralStudly` method converts a singular word string formatted in studly caps case to its plural form. This function currently only supports the English language:
The `Str::pluralStudly` method converts a singular word string formatted in studly caps case to its plural form. This function supports [any of the languages support by Laravel's pluralizer](/docs/{{version}}/localization#pluralization-language):

use Illuminate\Support\Str;

Expand Down Expand Up @@ -1721,7 +1721,7 @@ The `Str::reverse` method reverses the given string:
<a name="method-str-singular"></a>
#### `Str::singular()` {.collection-method}

The `Str::singular` method converts a string to its singular form. This function currently only supports the English language:
The `Str::singular` method converts a string to its singular form. This function supports [any of the languages support by Laravel's pluralizer](/docs/{{version}}/localization#pluralization-language):

use Illuminate\Support\Str;

Expand Down Expand Up @@ -2539,7 +2539,7 @@ The `pipe` method allows you to transform the string by passing its current valu
<a name="method-fluent-str-plural"></a>
#### `plural` {.collection-method}

The `plural` method converts a singular word string to its plural form. This function currently only supports the English language:
The `plural` method converts a singular word string to its plural form. This function supports [any of the languages support by Laravel's pluralizer](/docs/{{version}}/localization#pluralization-language):

use Illuminate\Support\Str;

Expand Down Expand Up @@ -2683,7 +2683,7 @@ The `scan` method parses input from a string into a collection according to a fo
<a name="method-fluent-str-singular"></a>
#### `singular` {.collection-method}

The `singular` method converts a string to its singular form. This function currently only supports the English language:
The `singular` method converts a string to its singular form. This function supports [any of the languages support by Laravel's pluralizer](/docs/{{version}}/localization#pluralization-language):

use Illuminate\Support\Str;

Expand Down
22 changes: 22 additions & 0 deletions localization.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- [Introduction](#introduction)
- [Configuring The Locale](#configuring-the-locale)
- [Pluralization Language](#pluralization-language)
- [Defining Translation Strings](#defining-translation-strings)
- [Using Short Keys](#using-short-keys)
- [Using Translation Strings As Keys](#using-translation-strings-as-keys)
Expand Down Expand Up @@ -67,6 +68,27 @@ You may use the `currentLocale` and `isLocale` methods on the `App` facade to de
//
}

<a name="pluralization-language"></a>
### Pluralization Language

You may instruct Laravel's "pluralizer", which is used by Eloquent and other portions of the framework to convert singular strings to plural strings, to use a language other than English. This may be accomplished by invoking the `useLanguage` method within the `boot` method of one of your application's service providers. The pluralizer's currently supported languages are: `french`, `norwegian-bokmal`, `portuguese`, `spanish`, and `turkish`:

use Illuminate\Support\Pluralizer;

/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Pluralizer::useLanguage('spanish');

// ...
}

> {note} If you customize the pluralizer's language, you should explicitly define your Eloquent model's [table names](/docs/{{version}}/eloquent#table-names).

<a name="defining-translation-strings"></a>
## Defining Translation Strings

Expand Down