From 23e03fab26d932f35906c61e441cb676d5833ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar?= Date: Thu, 21 Apr 2022 16:50:19 -0300 Subject: [PATCH 1/2] added Pluralizer::useLanguage documentation --- controllers.md | 8 ++++---- helpers.md | 10 +++++----- localization.md | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/controllers.md b/controllers.md index 15425185d9a..6379faa3015 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: +It's also possible to [change the pluralization rules](/docs/{{version}}/localization#changing-pluralization-rules) for better parameter names. 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..876a06a6ea3 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 [other languages](/docs/{{version}}/localization#changing-pluralization-rules): 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 [other languages](/docs/{{version}}/localization#changing-pluralization-rules): 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 [other languages](/docs/{{version}}/localization#changing-pluralization-rules): 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 [other languages](/docs/{{version}}/localization#changing-pluralization-rules): 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 [other languages](/docs/{{version}}/localization#changing-pluralization-rules): use Illuminate\Support\Str; diff --git a/localization.md b/localization.md index faf658f3681..5653023716b 100644 --- a/localization.md +++ b/localization.md @@ -67,6 +67,29 @@ You may use the `currentLocale` and `isLocale` methods on the `App` facade to de // } + +### Changing Pluralization rules + +It's also possible to change Laravels's default pluralization rules from a set of available languages other than english: 'french', 'norwegian-bokmal', 'portuguese', 'spanish' and 'turkish', see [Doctrine/Inflector](https://www.doctrine-project.org/projects/inflector.html) for details. This can be done at the `boot` method within your application's `App\Providers\AppServiceProvider`: + + use Illuminate\Support\Pluralizer; + + // ... + + /** + * Bootstrap any application services. + * + * @return void + */ + public function boot() + { + Pluralizer::useLanguage('spanish'); + + // ... + } + +> {note} When using a different language rule, the `User` model might need to have its [table name](/docs/{{version}}/eloquent#table-names) manually set to `users`, as the word "user" may have a different plural form in other languages. + ## Defining Translation Strings From 382fcaa6d072e51940e4185ae17cb5a6b69e40a8 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 22 Apr 2022 10:01:53 -0500 Subject: [PATCH 2/2] formatting --- controllers.md | 2 +- helpers.md | 10 +++++----- localization.md | 11 +++++------ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/controllers.md b/controllers.md index 6379faa3015..9cadef58600 100644 --- a/controllers.md +++ b/controllers.md @@ -343,7 +343,7 @@ By default, `Route::resource` will create resource URIs using English verbs and // ... } -It's also possible to [change the pluralization rules](/docs/{{version}}/localization#changing-pluralization-rules) for better parameter names. 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: +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: /publicacion/crear diff --git a/helpers.md b/helpers.md index 876a06a6ea3..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 supports [other languages](/docs/{{version}}/localization#changing-pluralization-rules): +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 supports [other languages](/docs/{{version}}/localization#changing-pluralization-rules): +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 supports [other languages](/docs/{{version}}/localization#changing-pluralization-rules): +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 supports [other languages](/docs/{{version}}/localization#changing-pluralization-rules): +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 supports [other languages](/docs/{{version}}/localization#changing-pluralization-rules): +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 5653023716b..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,15 +68,13 @@ You may use the `currentLocale` and `isLocale` methods on the `App` facade to de // } - -### Changing Pluralization rules + +### Pluralization Language -It's also possible to change Laravels's default pluralization rules from a set of available languages other than english: 'french', 'norwegian-bokmal', 'portuguese', 'spanish' and 'turkish', see [Doctrine/Inflector](https://www.doctrine-project.org/projects/inflector.html) for details. This can be done at the `boot` method within your application's `App\Providers\AppServiceProvider`: +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. * @@ -88,7 +87,7 @@ It's also possible to change Laravels's default pluralization rules from a set o // ... } -> {note} When using a different language rule, the `User` model might need to have its [table name](/docs/{{version}}/eloquent#table-names) manually set to `users`, as the word "user" may have a different plural form in other languages. +> {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