Skip to content

Commit c3fc921

Browse files
authored
lang updates (laravel#8529)
1 parent 76a6ee9 commit c3fc921

File tree

7 files changed

+52
-25
lines changed

7 files changed

+52
-25
lines changed

fortify.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,9 @@ The `/forgot-password` endpoint expects a string `email` field. The name of this
423423

424424
If the password reset link request was successful, Fortify will redirect the user back to the `/forgot-password` endpoint and send an email to the user with a secure link they can use to reset their password. If the request was an XHR request, a 200 HTTP response will be returned.
425425

426-
After being redirected back to the `/forgot-password` endpoint after a successful request, the `status` session variable may be used to display the status of the password reset link request attempt. The value of this session variable will match one of the translation strings defined within your application's `passwords` [language file](/docs/{{version}}/localization):
426+
After being redirected back to the `/forgot-password` endpoint after a successful request, the `status` session variable may be used to display the status of the password reset link request attempt.
427+
428+
The value of the `$status` session variable will match one of the translation strings defined within your application's `passwords` [language file](/docs/{{version}}/localization). If you would like to customize this value and have not published Laravel's language files, you may do so via the `lang:publish` Artisan command:
427429

428430
```html
429431
@if (session('status'))

helpers.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,9 @@ The `lang_path` function returns the fully qualified path to your application's
12201220

12211221
$path = lang_path('en/messages.php');
12221222

1223+
> **Note**
1224+
> By default, the Laravel application skeleton does not include the `lang` directory. If you would like to customize Laravel's language files, you may publish them via the `lang:publish` Artisan command.
1225+
12231226
<a name="method-mix"></a>
12241227
#### `mix()` {.collection-method}
12251228

@@ -1260,7 +1263,7 @@ The `storage_path` function returns the fully qualified path to your application
12601263
<a name="method-__"></a>
12611264
#### `__()` {.collection-method}
12621265

1263-
The `__` function translates the given translation string or translation key using your [localization files](/docs/{{version}}/localization):
1266+
The `__` function translates the given translation string or translation key using your [language files](/docs/{{version}}/localization):
12641267

12651268
echo __('Welcome to our application');
12661269

@@ -2131,7 +2134,7 @@ If no argument is provided to the `str` function, the function returns an instan
21312134
<a name="method-trans"></a>
21322135
#### `trans()` {.collection-method}
21332136

2134-
The `trans` function translates the given translation key using your [localization files](/docs/{{version}}/localization):
2137+
The `trans` function translates the given translation key using your [language files](/docs/{{version}}/localization):
21352138

21362139
echo trans('messages.welcome');
21372140

localization.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Localization
22

33
- [Introduction](#introduction)
4+
- [Publishing The Language Files](#publishing-the-language-files)
45
- [Configuring The Locale](#configuring-the-locale)
56
- [Pluralization Language](#pluralization-language)
67
- [Defining Translation Strings](#defining-translation-strings)
@@ -14,9 +15,12 @@
1415
<a name="introduction"></a>
1516
## Introduction
1617

18+
> **Note**
19+
> By default, the Laravel application skeleton does not include the `lang` directory. If you would like to customize Laravel's language files, you may publish them via the `lang:publish` Artisan command.
20+
1721
Laravel's localization features provide a convenient way to retrieve strings in various languages, allowing you to easily support multiple languages within your application.
1822

19-
Laravel provides two ways to manage translation strings. First, language strings may be stored in files within the `lang` directory. Within this directory, there may be subdirectories for each language supported by the application. This is the approach Laravel uses to manage translation strings for built-in Laravel features such as validation error messages:
23+
Laravel provides two ways to manage translation strings. First, language strings may be stored in files within the application's `lang` directory. Within this directory, there may be subdirectories for each language supported by the application. This is the approach Laravel uses to manage translation strings for built-in Laravel features such as validation error messages:
2024

2125
/lang
2226
/en
@@ -32,6 +36,15 @@ Or, translation strings may be defined within JSON files that are placed within
3236

3337
We'll discuss each approach to managing translation strings within this documentation.
3438

39+
<a name="publishing-the-language-files"></a>
40+
### Publishing The Language Files
41+
42+
By default, the Laravel application skeleton does not include the `lang` directory. If you would like to customize Laravel's language files or create your own, you should scaffold the `lang` directory via the `lang:publish` Artisan command. The `lang:publish` command will create the `lang` directory in your application and publish the default set of language files used by Laravel:
43+
44+
```shell
45+
php artisan lang:publish
46+
```
47+
3548
<a name="configuring-the-locale"></a>
3649
### Configuring The Locale
3750

@@ -120,7 +133,7 @@ All language files return an array of keyed strings. For example:
120133

121134
For applications with a large number of translatable strings, defining every string with a "short key" can become confusing when referencing the keys in your views and it is cumbersome to continually invent keys for every translation string supported by your application.
122135

123-
For this reason, Laravel also provides support for defining translation strings using the "default" translation of the string as the key. Translation files that use translation strings as keys are stored as JSON files in the `lang` directory. For example, if your application has a Spanish translation, you should create a `lang/es.json` file:
136+
For this reason, Laravel also provides support for defining translation strings using the "default" translation of the string as the key. Language files that use translation strings as keys are stored as JSON files in the `lang` directory. For example, if your application has a Spanish translation, you should create a `lang/es.json` file:
124137

125138
```json
126139
{
@@ -130,7 +143,7 @@ For this reason, Laravel also provides support for defining translation strings
130143

131144
#### Key / File Conflicts
132145

133-
You should not define translation string keys that conflict with other translation filenames. For example, translating `__('Action')` for the "NL" locale while a `nl/action.php` file exists but a `nl.json` file does not exist will result in the translator returning the contents of `nl/action.php`.
146+
You should not define translation string keys that conflict with other translation filenames. For example, translating `__('Action')` for the "NL" locale while a `nl/action.php` file exists but a `nl.json` file does not exist will result in the translator returning the entire contents of `nl/action.php`.
134147

135148
<a name="retrieving-translation-strings"></a>
136149
## Retrieving Translation Strings

packages.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- [Configuration](#configuration)
99
- [Migrations](#migrations)
1010
- [Routes](#routes)
11-
- [Translations](#translations)
11+
- [Language Files](#language-files)
1212
- [Views](#views)
1313
- [View Components](#view-components)
1414
- ["About" Artisan Command](#about-artisan-command)
@@ -80,7 +80,7 @@ You may disable package discovery for all packages using the `*` character insid
8080
<a name="service-providers"></a>
8181
## Service Providers
8282

83-
[Service providers](/docs/{{version}}/providers) are the connection point between your package and Laravel. A service provider is responsible for binding things into Laravel's [service container](/docs/{{version}}/container) and informing Laravel where to load package resources such as views, configuration, and localization files.
83+
[Service providers](/docs/{{version}}/providers) are the connection point between your package and Laravel. A service provider is responsible for binding things into Laravel's [service container](/docs/{{version}}/container) and informing Laravel where to load package resources such as views, configuration, and language files.
8484

8585
A service provider extends the `Illuminate\Support\ServiceProvider` class and contains two methods: `register` and `boot`. The base `ServiceProvider` class is located in the `illuminate/support` Composer package, which you should add to your own package's dependencies. To learn more about the structure and purpose of service providers, check out [their documentation](/docs/{{version}}/providers).
8686

@@ -157,10 +157,10 @@ If your package contains [database migrations](/docs/{{version}}/migrations), yo
157157

158158
Once your package's migrations have been registered, they will automatically be run when the `php artisan migrate` command is executed. You do not need to export them to the application's `database/migrations` directory.
159159

160-
<a name="translations"></a>
161-
### Translations
160+
<a name="language-files"></a>
161+
### Language Files
162162

163-
If your package contains [translation files](/docs/{{version}}/localization), you may use the `loadTranslationsFrom` method to inform Laravel how to load them. For example, if your package is named `courier`, you should add the following to your service provider's `boot` method:
163+
If your package contains [language files](/docs/{{version}}/localization), you may use the `loadTranslationsFrom` method to inform Laravel how to load them. For example, if your package is named `courier`, you should add the following to your service provider's `boot` method:
164164

165165
/**
166166
* Bootstrap any package services.
@@ -170,14 +170,14 @@ If your package contains [translation files](/docs/{{version}}/localization), yo
170170
$this->loadTranslationsFrom(__DIR__.'/../lang', 'courier');
171171
}
172172

173-
Package translations are referenced using the `package::file.line` syntax convention. So, you may load the `courier` package's `welcome` line from the `messages` file like so:
173+
Package translation lines are referenced using the `package::file.line` syntax convention. So, you may load the `courier` package's `welcome` line from the `messages` file like so:
174174

175175
echo trans('courier::messages.welcome');
176176

177-
<a name="publishing-translations"></a>
178-
#### Publishing Translations
177+
<a name="publishing-language-files"></a>
178+
#### Publishing Language Files
179179

180-
If you would like to publish your package's translations to the application's `lang/vendor` directory, you may use the service provider's `publishes` method. The `publishes` method accepts an array of package paths and their desired publish locations. For example, to publish the translation files for the `courier` package, you may do the following:
180+
If you would like to publish your package's language files to the application's `lang/vendor` directory, you may use the service provider's `publishes` method. The `publishes` method accepts an array of package paths and their desired publish locations. For example, to publish the language files for the `courier` package, you may do the following:
181181

182182
/**
183183
* Bootstrap any package services.
@@ -191,7 +191,7 @@ If you would like to publish your package's translations to the application's `l
191191
]);
192192
}
193193

194-
Now, when users of your package execute Laravel's `vendor:publish` Artisan command, your package's translations will be published to the specified publish location.
194+
Now, when users of your package execute Laravel's `vendor:publish` Artisan command, your package's language files will be published to the specified publish location.
195195

196196
<a name="views"></a>
197197
### Views

passwords.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ Before moving on, let's examine this route in more detail. First, the request's
8686

8787
The `sendResetLink` method returns a "status" slug. This status may be translated using Laravel's [localization](/docs/{{version}}/localization) helpers in order to display a user-friendly message to the user regarding the status of their request. The translation of the password reset status is determined by your application's `lang/{lang}/passwords.php` language file. An entry for each possible value of the status slug is located within the `passwords` language file.
8888

89+
> **Note**
90+
> By default, the Laravel application skeleton does not include the `lang` directory. If you would like to customize Laravel's language files, you may publish them via the `lang:publish` Artisan command.
91+
8992
You may be wondering how Laravel knows how to retrieve the user record from your application's database when calling the `Password` facade's `sendResetLink` method. The Laravel password broker utilizes your authentication system's "user providers" to retrieve database records. The user provider used by the password broker is configured within the `passwords` configuration array of your `config/auth.php` configuration file. To learn more about writing custom user providers, consult the [authentication documentation](/docs/{{version}}/authentication#adding-custom-user-providers).
9093

9194
> **Note**
@@ -146,7 +149,7 @@ Before moving on, let's examine this route in more detail. First, the request's
146149

147150
If the token, email address, and password given to the password broker are valid, the closure passed to the `reset` method will be invoked. Within this closure, which receives the user instance and the plain-text password provided to the password reset form, we may update the user's password in the database.
148151

149-
The `reset` method returns a "status" slug. This status may be translated using Laravel's [localization](/docs/{{version}}/localization) helpers in order to display a user-friendly message to the user regarding the status of their request. The translation of the password reset status is determined by your application's `lang/{lang}/passwords.php` language file. An entry for each possible value of the status slug is located within the `passwords` language file.
152+
The `reset` method returns a "status" slug. This status may be translated using Laravel's [localization](/docs/{{version}}/localization) helpers in order to display a user-friendly message to the user regarding the status of their request. The translation of the password reset status is determined by your application's `lang/{lang}/passwords.php` language file. An entry for each possible value of the status slug is located within the `passwords` language file. If your application does not contain a `lang` directory, you may create it using the `lang:publish` Artisan command.
150153

151154
Before moving on, you may be wondering how Laravel knows how to retrieve the user record from your application's database when calling the `Password` facade's `reset` method. The Laravel password broker utilizes your authentication system's "user providers" to retrieve database records. The user provider used by the password broker is configured within the `passwords` configuration array of your `config/auth.php` configuration file. To learn more about writing custom user providers, consult the [authentication documentation](/docs/{{version}}/authentication#adding-custom-user-providers).
152155

structure.md

-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
- [The `bootstrap` Directory](#the-bootstrap-directory)
77
- [The `config` Directory](#the-config-directory)
88
- [The `database` Directory](#the-database-directory)
9-
- [The `lang` Directory](#the-lang-directory)
109
- [The `public` Directory](#the-public-directory)
1110
- [The `resources` Directory](#the-resources-directory)
1211
- [The `routes` Directory](#the-routes-directory)
@@ -59,11 +58,6 @@ The `config` directory, as the name implies, contains all of your application's
5958

6059
The `database` directory contains your database migrations, model factories, and seeds. If you wish, you may also use this directory to hold an SQLite database.
6160

62-
<a name="the-lang-directory"></a>
63-
#### The Lang Directory
64-
65-
The `lang` directory houses all of your application's language files.
66-
6761
<a name="the-public-directory"></a>
6862
#### The Public Directory
6963

validation.md

+14-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ So, in our example, the user will be redirected to our controller's `create` met
199199

200200
Laravel's built-in validation rules each have an error message that is located in your application's `lang/en/validation.php` file. Within this file, you will find a translation entry for each validation rule. You are free to change or modify these messages based on the needs of your application.
201201

202-
In addition, you may copy this file to another translation language directory to translate the messages for your application's language. To learn more about Laravel localization, check out the complete [localization documentation](/docs/{{version}}/localization).
202+
In addition, you may copy this file to another language directory to translate the messages for your application's language. To learn more about Laravel localization, check out the complete [localization documentation](/docs/{{version}}/localization).
203+
204+
> **Warning**
205+
> By default, the Laravel application skeleton does not include the `lang` directory. If you would like to customize Laravel's language files, you may publish them via the `lang:publish` Artisan command.
203206
204207
<a name="quick-xhr-requests-and-validation"></a>
205208
#### XHR Requests & Validation
@@ -736,7 +739,10 @@ The `has` method may be used to determine if any error messages exist for a give
736739

737740
Laravel's built-in validation rules each have an error message that is located in your application's `lang/en/validation.php` file. Within this file, you will find a translation entry for each validation rule. You are free to change or modify these messages based on the needs of your application.
738741

739-
In addition, you may copy this file to another translation language directory to translate the messages for your application's language. To learn more about Laravel localization, check out the complete [localization documentation](/docs/{{version}}/localization).
742+
In addition, you may copy this file to another language directory to translate the messages for your application's language. To learn more about Laravel localization, check out the complete [localization documentation](/docs/{{version}}/localization).
743+
744+
> **Warning**
745+
> By default, the Laravel application skeleton does not include the `lang` directory. If you would like to customize Laravel's language files, you may publish them via the `lang:publish` Artisan command.
740746
741747
<a name="custom-messages-for-specific-attributes"></a>
742748
#### Custom Messages For Specific Attributes
@@ -759,6 +765,9 @@ Many of Laravel's built-in error messages include an `:attribute` placeholder th
759765
'email' => 'email address',
760766
],
761767

768+
> **Warning**
769+
> By default, the Laravel application skeleton does not include the `lang` directory. If you would like to customize Laravel's language files, you may publish them via the `lang:publish` Artisan command.
770+
762771
<a name="specifying-values-in-language-files"></a>
763772
### Specifying Values In Language Files
764773

@@ -782,6 +791,9 @@ Instead of displaying `cc` as the payment type value, you may specify a more use
782791
],
783792
],
784793

794+
> **Warning**
795+
> By default, the Laravel application skeleton does not include the `lang` directory. If you would like to customize Laravel's language files, you may publish them via the `lang:publish` Artisan command.
796+
785797
After defining this value, the validation rule will produce the following error message:
786798

787799
```none

0 commit comments

Comments
 (0)