This guide helps you replace all localization strings in the form of {{ __('...') }} with the plain text inside the __('...') function in Laravel projects.
-
Pattern: Use this regular expression to match the
{{ __('...') }}structure:\{\{\s*__\(\s*['"]([^'"]*)['"]\s*\)\s*\}\}
-
Explanation:
\{\{: Matches the opening{{and is escaped with backslashes.\s*: Matches optional spaces.__\(\s*['"]([^'"]*)['"]\s*\): Captures the text inside the__('...')function. The([^'"]*)captures the inner content.\}\}: Matches the closing}}.
In the Replace box, use:
$1
This will replace the matched pattern with just the captured text inside the __('...').
-
Open the Find and Replace tool:
- In VSCode: Press
Ctrl + HorCmd + H. - Make sure to enable regex mode (the
.*button).
- In VSCode: Press
-
Search:
- Paste the provided regular expression into the Find box.
-
Replace:
- Use
$1in the Replace box.
- Use
-
Execute:
- Review the matches and click Replace All to replace all occurrences of
{{ __('...') }}with the inner text.
- Review the matches and click Replace All to replace all occurrences of
{{ __('Log in') }}
{{ __('Register') }}Log in
Register- Backup: Before running this across your project, ensure you have proper backups or use version control.