Skip to content

Commit cd9f6cc

Browse files
[9.x] Added Pluralizer::useLanguage documentation (#7894)
* added Pluralizer::useLanguage documentation * formatting Co-authored-by: Taylor Otwell <[email protected]>
1 parent 0683e2b commit cd9f6cc

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

Diff for: controllers.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ When using a custom keyed implicit binding as a nested route parameter, Laravel
326326
<a name="restful-localizing-resource-uris"></a>
327327
### Localizing Resource URIs
328328

329-
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`:
329+
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`:
330330

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

346-
Once the verbs have been customized, a resource route registration such as `Route::resource('fotos', PhotoController::class)` will produce the following URIs:
346+
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:
347347

348-
/fotos/crear
348+
/publicacion/crear
349349

350-
/fotos/{foto}/editar
350+
/publicacion/{publicaciones}/editar
351351

352352
<a name="restful-supplementing-resource-controllers"></a>
353353
### Supplementing Resource Controllers

Diff for: helpers.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,7 @@ The `Str::padRight` method wraps PHP's `str_pad` function, padding the right sid
15831583
<a name="method-str-plural"></a>
15841584
#### `Str::plural()` {.collection-method}
15851585

1586-
The `Str::plural` method converts a singular word string to its plural form. This function currently only supports the English language:
1586+
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):
15871587

15881588
use Illuminate\Support\Str;
15891589

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

1613-
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:
1613+
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):
16141614

16151615
use Illuminate\Support\Str;
16161616

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

1724-
The `Str::singular` method converts a string to its singular form. This function currently only supports the English language:
1724+
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):
17251725

17261726
use Illuminate\Support\Str;
17271727

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

2542-
The `plural` method converts a singular word string to its plural form. This function currently only supports the English language:
2542+
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):
25432543

25442544
use Illuminate\Support\Str;
25452545

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

2686-
The `singular` method converts a string to its singular form. This function currently only supports the English language:
2686+
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):
26872687

26882688
use Illuminate\Support\Str;
26892689

Diff for: localization.md

+22
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

71+
<a name="pluralization-language"></a>
72+
### Pluralization Language
73+
74+
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`:
75+
76+
use Illuminate\Support\Pluralizer;
77+
78+
/**
79+
* Bootstrap any application services.
80+
*
81+
* @return void
82+
*/
83+
public function boot()
84+
{
85+
Pluralizer::useLanguage('spanish');
86+
87+
// ...
88+
}
89+
90+
> {note} If you customize the pluralizer's language, you should explicitly define your Eloquent model's [table names](/docs/{{version}}/eloquent#table-names).
91+
7092
<a name="defining-translation-strings"></a>
7193
## Defining Translation Strings
7294

0 commit comments

Comments
 (0)