Skip to content
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

Localization: Add section about handling missing translation strings. #9147

Merged
merged 2 commits into from
Nov 21, 2023
Merged
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
22 changes: 22 additions & 0 deletions localization.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [Retrieving Translation Strings](#retrieving-translation-strings)
- [Replacing Parameters In Translation Strings](#replacing-parameters-in-translation-strings)
- [Pluralization](#pluralization)
- [Handling Missing Translation Strings](#handling-missing-translation-strings)
- [Overriding Package Language Files](#overriding-package-language-files)

<a name="introduction"></a>
Expand Down Expand Up @@ -233,6 +234,27 @@ If you would like to display the integer value that was passed to the `trans_cho

'apples' => '{0} There are none|{1} There is one|[2,*] There are :count',

<a name="handling-missing-translation-strings"></a>
### Handling Missing Translation Strings

Typically, when attempting to translate a string that does not have a corresponding key in your language files, Laravel will return the translation string key.

You may customize or intercept this behavior using the `handleMissingKeysUsing` method. Typically, you should invoke this method in the `boot` method of your application's `AppServiceProvider`:

use Illuminate\Support\Facades\Lang;

/**
* Bootstrap any application services.
*/
public function boot(): void
{
Lang::handleMissingKeysUsing(function (string $key, array $replacements, string $locale) {
info("Missing translation key [$key] detected.");

return $key;
});
}

<a name="overriding-package-language-files"></a>
## Overriding Package Language Files

Expand Down