• Reading time ~ 1 min
  • 14.03.2023

HTML String Affixer is a package for Laravel to make projects multilingual. This package finds text strings in HTML and replaces them with a localization function:

{{-- Before --}}
<p>Some nice string</p>

{{-- After --}}
<p>{{ __('Some nice string') }}</p>

This tool can be used with any .jsx, .vue, or .twig file as well, with customizable file prefixes and suffixes. The package's main features include:

  • Finds your HTML visible strings and replaces them with affixed one
  • Prefix and Suffixes are customizable (default {{ __(' and ') }})
  • If a string contains one of the warning characters, it will not replace but prints out the location:
  • If a string contains one of the ignoring characters, it just ignores the string
  • Ignore characters and warning characters are customizable from the JSON config file ("ignore" and "warnings")

This package supports configuration, which might look like the following JSON file:

{
  "folder": "resources/views",
  "prefix": "{{ __('",
  "suffix": "') }}",
  "ignore": ["#", "_", ">", "^", "*", "="],
  "warnings": ["%", "{", "(", "}", ")", "$", "'"]
}

You can then replace strings with translations using the following command:

./vendor/bin/hsa replace

# Or on Windows
./vendor/bin/hsawin replace

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297