Skip to content

Instantly share code, notes, and snippets.

@Maxiviper117
Created October 5, 2024 20:00
Show Gist options
  • Select an option

  • Save Maxiviper117/a1a198f1d3ba77e144cefe946d2939bc to your computer and use it in GitHub Desktop.

Select an option

Save Maxiviper117/a1a198f1d3ba77e144cefe946d2939bc to your computer and use it in GitHub Desktop.
Replacing Localization Strings in Laravel in Vscode

Replacing Localization Strings in Laravel

This guide helps you replace all localization strings in the form of {{ __('...') }} with the plain text inside the __('...') function in Laravel projects.

Regular Expression for Search

  1. Pattern: Use this regular expression to match the {{ __('...') }} structure:

    \{\{\s*__\(\s*['"]([^'"]*)['"]\s*\)\s*\}\}
  2. 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 }}.

Replacement

In the Replace box, use:

$1

This will replace the matched pattern with just the captured text inside the __('...').

Step-by-Step Instructions

  1. Open the Find and Replace tool:

    • In VSCode: Press Ctrl + H or Cmd + H.
    • Make sure to enable regex mode (the .* button).
  2. Search:

    • Paste the provided regular expression into the Find box.
  3. Replace:

    • Use $1 in the Replace box.
  4. Execute:

    • Review the matches and click Replace All to replace all occurrences of {{ __('...') }} with the inner text.

Example

Before:

{{ __('Log in') }}
{{ __('Register') }}

After:

Log in
Register

Tools and Tips

  • Backup: Before running this across your project, ensure you have proper backups or use version control.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment