diff --git a/controllers.md b/controllers.md index 15425185d9a..9cadef58600 100644 --- a/controllers.md +++ b/controllers.md @@ -326,7 +326,7 @@ When using a custom keyed implicit binding as a nested route parameter, Laravel ### 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. @@ -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 ### Supplementing Resource Controllers diff --git a/helpers.md b/helpers.md index 42dcb519b39..e2a03bb928c 100644 --- a/helpers.md +++ b/helpers.md @@ -1583,7 +1583,7 @@ The `Str::padRight` method wraps PHP's `str_pad` function, padding the right sid #### `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; @@ -1610,7 +1610,7 @@ You may provide an integer as a second argument to the function to retrieve the #### `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; @@ -1721,7 +1721,7 @@ The `Str::reverse` method reverses the given string: #### `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; @@ -2539,7 +2539,7 @@ The `pipe` method allows you to transform the string by passing its current valu #### `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; @@ -2683,7 +2683,7 @@ The `scan` method parses input from a string into a collection according to a fo #### `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; diff --git a/localization.md b/localization.md index faf658f3681..a934480d061 100644 --- a/localization.md +++ b/localization.md @@ -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) @@ -67,6 +68,27 @@ You may use the `currentLocale` and `isLocale` methods on the `App` facade to de // } + +### 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). + ## Defining Translation Strings