PHPackages                             maestroerror/html-strings-affixer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. maestroerror/html-strings-affixer

ActiveLibrary[CLI &amp; Console](/categories/cli)

maestroerror/html-strings-affixer
=================================

Finds texts in HTML and replaces it with suffixed and prefixed string

1.2.2(2y ago)925.5k2MITGo

Since Jul 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/MaestroError/html-strings-affixer)[ Packagist](https://packagist.org/packages/maestroerror/html-strings-affixer)[ RSS](/packages/maestroerror-html-strings-affixer/feed)WikiDiscussions maestro Synced 1mo ago

READMEChangelog (10)DependenciesVersions (13)Used By (0)

html-strings-affixer
====================

[](#html-strings-affixer)

CLI tool that finds texts in HTML and replaces it with suffixed and prefixed string. Originally developed to replace strings with localization function in blade file:
`Some nice string` -&gt; `{{ __('Some nice string') }}`
But can be used in any file which contains html (".jsx", ".vue", ".twig") with same purpose. Of course, prefix and suffix are customizable

*JavaScript version is already available [here](https://github.com/MaestroError/hsa-js) ([hsa-js](https://github.com/MaestroError/hsa-js))*

#### Quick start

[](#quick-start)

Check out a little [article](https://medium.com/towardsdev/translate-laravel-blade-files-easily-f3753f5395bd) on Medium about the tool.

Navigation
==========

[](#navigation)

- [Installation](#installation)
    - [Composer](#composer)
    - [Linux/Unix](#linuxunix)
    - [Windows](#windows)
    - [MacOS](#macos)
    - [From source](#from-source)
- [Features](#features)
- [Config file](#config-file)
    - [JSON object and descriptions](#json-object-and-descriptions)
- [Commands](#commands)
    - [Replace command options](#replace-command-options)
    - [Check command options](#check-command-options)
- [Usage](#usage)
    - [Just affix it!](#just-affix-it)
    - [Force replace](#force-replace)
    - [One File](#work-with-one-file)
    - [Too many warnings](#too-many-warning)
    - [Choose Executable](#executables)
- [Support](#support)

Installation
============

[](#installation)

### Composer

[](#composer)

It is already available in composer now, you can require it:
`composer require maestroerror/html-strings-affixer --dev`.
After installation it is accessible by:

- Linux: `./vendor/bin/hsa`
- Windows: `./vendor/bin/hsawin`
- MacOS: `./vendor/bin/hsamac`
- MacOS arm64 (m1): `./vendor/bin/hsamacm1`

### Linux/Unix

[](#linuxunix)

**Step 1: Download**
Download binary [file](https://github.com/MaestroError/html-strings-affixer/releases/latest/download/hsa) with `wget https://github.com/MaestroError/html-strings-affixer/releases/latest/download/hsa`

**Step 2: Make it executable**
Run in directory with downloaded file `chmod a+x ./hsa` (Use sudo if permission is required)

**Step 3: Execution**
You can move it in directory where you need to use and just execute with `./hsa [command] [-args]` or Make it available viw command line.

**Step 4: Command line *(optional)***
Find your bin folder (`/usr/bin`, `/usr/sbin` or `~/bin`), or make it with `cd ~/ && mkdir bin` and Symlink (`ln -s $~/path/to/directory/hsa ~/bin/hsa`) or move/copy binary file in **bin** directory. After it you can use app in cli with "hsa" command. Try: `hsa check`

### Windows

[](#windows)

Download binary [file](https://github.com/MaestroError/html-strings-affixer/releases/latest/download/hsa.exe) or [Zip](https://github.com/MaestroError/html-strings-affixer/releases/latest/download/hsawin.zip). Get "hsa.exe" file in needed directory and run with ".\\hsa.exe"

### MacOS

[](#macos)

Download an [archive](https://github.com/MaestroError/html-strings-affixer/releases/latest/download/hsamac.zip), Unzip it, get "hsamac" or "hsamacm1" file in needed directory, give to it executable permissions and run with `./hsamac` or `./hsamacm1`

### From source

[](#from-source)

If you have [golang](https://go.dev/doc/install) installed, you can clone this repo and run `go install` or `go build` for binary file

Features
========

[](#features)

- Finds your HTML visible strings and replaces with affixed one
- Prefix and Suffix are customizable
    - By default set as "{{ \_\_('" and "') }}"
- If string contains one of the warning characters, it not replaces, but prints out location:
    - So it will not replace string with variable like "Price: {{$price}}", if you have '{' in warning character, it will give you exact location(file:line) to make it translatable manually
- If string contains one of the ignoring characters, it just ignores string
    - For example, if your string is math expression like 4 \_ 20 = 80 and you have "\_" in ignoring characters, it will just ignore it
- This characters are set by default as:
    - ignore: "#", "\_", "&gt;", "^", "\*", "="
    - warnings: "%", "{", "(", "}", ")", "$", "'"
- Ignore characters and warning characters are customizable from JSON config file ("ignore" and "warnings")

Config file
===========

[](#config-file)

You need to create "affixer.json" file in directory, from where you will run html-strings-affixer. You can find an [example](https://github.com/MaestroError/html-strings-affixer/blob/maestro/bin/affixer-example.json) in bin folder of this repository (bin/affixer-example.json).
*Alternativly you can run app without config file in your working directory and it will offer you to create one from example*

### JSON object and descriptions

[](#json-object-and-descriptions)

```
    // Scanning
    *(string) "folder" - just folder to scan
    *(array) "file_types" - Parses file only with given extensions
    (array) "ignore_names" - ignores files and folders with given names

    // Parse
    (array) "ignore" - ignores strings which contains given character (Group of characters not allowed, only single characters)
    (array) "warnings" - Warns about strings which contains given characters (not replaces)
    (array) "methods" - Uses only given parse methods. Available: text, placeholder, alt, title, hashtag

    // Replace
    *(string) "prefix" - Prefix to set
    *(string) "suffix" - Suffix to set
    (bool) "force" - If true, git status check is ignored

    // Report
    (bool) "detailed" - if true, detailed report will be displayed
    (bool) "warn_as_Table" - if true, warnings will be displayed as table
    (bool) "report" - if true, warnings will be saved as JSON file

    // Log
    (string) "log_folder" - folder to store logs

```

Commands
========

[](#commands)

Available commands:

- **replace** - Main command, which makes replacement of strings
- **check** - Checks folder and gives report with files and count of found strings
- **clear-log** - If you use log\_folder config, logs are generated. this command clear all log files (Has no arguments)

Some configs you can pass as arguments, use `hsa [command] --help` to read more about command.

### *Replace* command options

[](#replace-command-options)

- -allowed="(string)" - allowed file types, separated by commas (**Required** for security reasons)
- -detailed - If passed, detailed report printed
- -file="(string)" - Use this argument to run command only on one file
- -folder="(string)" - Folder to scan (**Required**)
- -force - If passed, git status check is ignored
- -only="(string)" - Methods to use while parsing, separated by commas. Available: text, placeholder, alt, title, hashtag
- -prefix="(string)" - New prefix for strings (**Required**)
- -suffix="(string)" - New suffix for strings (**Required**)
- -report - if true, warnings will be saved as JSON file

### *Check* command options

[](#check-command-options)

- -allowed="(string)" - allowed file types, separated by commas (**Required**)
- -file="(string)" - Use this argument to run command only on one file
- -folder="(string)" - Folder to scan (**Required**)
- -only="(string)" - Methods to use while parsing, separated by commas. Available: text, placeholder, alt, title, hashtag
- -report - if true, warnings will be saved as JSON file

Usage
=====

[](#usage)

It is recommended to use tool with [config file](#config-file), where you can specify all needed info and use all features, that tool is providing. If you already have configured file you can easily run:

```
~$ ./vendor/bin/hsa check
# AND/OR
~$ ./vendor/bin/hsa replace

```

In this usage guide, we will cover some CLI use cases, but you can use them **alongside** with config file, because options provided from command line has **higher priority**. They re-write all passed options while specific run, but all **other configs** provided by JSON file stays same.

#### Just Affix it!

[](#just-affix-it)

For example, you can: Easily affix all html strings with @lang directive in templates folder. To do so, run:

```
./vendor/bin/hsa replace -folder="resources/views" -allowed=".blade.php" -prefix="@lang('" -suffix="')"

```

in another words:

```
hsa replace -folder="[Path/To/Your/Folder]" -allowed="[Allowed, File, Extensions]" -prefix="[StringToPrepend]" -suffix="[StringToAppend]"

```

*Note: Keep in mind that "@" character is not a part of default ignore or warning chars, you need to specify it via config file*

#### Force replace

[](#force-replace)

If you use git and have uncommitted changes, it is recommended to first commit or stash them and after run replace command, so hsa will ask you about it on every run. If you already tested the tool and you know what are you doing, you can use *-force* parameter to skip that prompt.

```
./vendor/bin/hsa replace -folder="views" -force

```

*Note: For now, HSA has not UNDO command, so be careful while running replace*

#### Work with one file

[](#work-with-one-file)

Sometimes you will need to perform some commands only on single file, to reduce memory usage, get smaller printed information and/or avoid unwanted changes. For that purpose you can use option *-file*:

```
./vendor/bin/hsa replace -file="resources/view/contact.blade.php"

```

#### Too many warning

[](#too-many-warning)

Sometimes with large project there are too many warning to check them via terminal. For such cases -report option could be helpful, it will generate JSON file with all warnings in it:

```
./vendor/bin/hsa check -report

```

Note that `-report` option is availabe for both, `replace` and `check` commands. Also, it can be set via JSON file as `report: true`.

#### Executables

[](#executables)

There are several executables for different platforms, choose your one and use it. They are working the exactly same way, you are changing just the executable file name in command.

- Linux: `./vendor/bin/hsa`
- Windows: `./vendor/bin/hsawin`
- MacOS: `./vendor/bin/hsamac`
- MacOS arm64 (m1): `./vendor/bin/hsamacm1`

*Note: I am planning to create single command, which will work for any platform, but for now, it is as it is 😄*

Support
=======

[](#support)

Support Our Work? 🌟 You can help us keep the code flowing by making a small donation. Every bit of support goes a long way in maintaining and improving our open-source contributions. Click the button below to contribute. Thank you for your generosity!

[![](https://github.com/MaestroError/resources/raw/maestro/buymeamilk/green-2.png)](https://www.buymeacoffee.com/maestroerror)

Or use QR code:

[![](https://github.com/MaestroError/resources/raw/maestro/buymeamilk/qr-code.png)](https://www.buymeacoffee.com/maestroerror)

---

---

### To Do

[](#to-do)

- Make check command to print files and found strings count +
- Create clear-log command and print logs size as message in bootstrap +
- Write documentation in readme file +
- Release #1 - 0.0.1 +
- register on packagist (Composer require) +

---

- Test linux binary on ubuntu +
- Add composer install instructions in docs +
- Add linux install instructions in documentation +
- Make windows exe/msi installer ?
- Standardize Json configs +
- Update example config file with all needed configs +
- Add warning characters and separate them from ignoring characters +
- Consider similar cases `Veelgestelde vragen over {{$serviceName}}` +
    - add OT-OT(Opening Tag) and CT-CT(Closing Tag) extractions in "text" group +
    - add CT-OT +
- Print warning characters strings as warnings (not replaced) with file and line on replace command +
- Add warnings count in check command +
- Update documentation +
- Generate files for bin folder +
- Next Release (Don't forget to add in release: hsa, hsa.exe, hsawin.zip and hsaInstaller.msi) +

---

- Use error handling instead some of default configs, when one is not specified (From CLI or Config file) +
    - Folder | File (not use default folder and check it before running commands) +
    - allowed +
    - prefix (for replace command) +
    - suffix (for replace command) +
- Fix error while using HSA out of git repo +
- Add success message function in reporter +
- Make warnings table in reporter +
- Make warnings as table controllable from config and add it in Docs +
- Test for latest changes +
- Next Release +

---

Updated 21/09/2023:

- Add --report option for detailed report (JSON) in check command ([issue](https://github.com/MaestroError/html-strings-affixer/issues/2)) +
- Add `@` and `{{--` in default ignore characters ([issue](https://github.com/MaestroError/html-strings-affixer/issues/3)) +
- Update regex to parse laravel comments correctly ([issue](https://github.com/MaestroError/html-strings-affixer/issues/5)) +
- Fix `index out of range [-1]` [issue](https://github.com/MaestroError/html-strings-affixer/issues/4) +
- Release +

---

- Make TrimSpaces controllable as configuration from JSON
- Handle errors to continue replacement on other files and add error location in output (report)
- Test for latest changes
- Next Release

### Upcoming

[](#upcoming)

- Write benchmarks for app
- Make app available by npm ([article](https://blog.bywachira.com/post/create-cli-with-golang-and-publish-on-npm))
- Install and configure goreleaser
- Refactor app with Cobra package
- Use log files to undo last changes in folder\_to\_scan from log\_folder (for dry run)
- add command: "watch" (for live updates) and "undo" (Undo last changes)
- Make single executable/command (Bridge) for any platform

#### Resources

[](#resources)

- [goreleaser](https://goreleaser.com/) +
- [go-npm](https://github.com/sanathkr/go-npm)
- [Developing and publishing modules](https://go.dev/doc/modules/developing)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~38 days

Recently: every ~95 days

Total

12

Last Release

971d ago

Major Versions

0.0.7 → 1.0.02022-09-06

### Community

Maintainers

![](https://www.gravatar.com/avatar/9b3015d66e88ffcecb330b381383fc9e343dbe1deffc3b62cff21d569901f17e?d=identicon)[maestroerror](/maintainers/maestroerror)

---

Top Contributors

[![MaestroError](https://avatars.githubusercontent.com/u/46760939?v=4)](https://github.com/MaestroError "MaestroError (153 commits)")[![actions-user](https://avatars.githubusercontent.com/u/65916846?v=4)](https://github.com/actions-user "actions-user (15 commits)")

---

Tags

cligolang-applicationhtml-stringhtml-strings-affixerhtml5laravel-localizationlaravel-multi-languagelaravel-package

### Embed Badge

![Health badge](/badges/maestroerror-html-strings-affixer/health.svg)

```
[![Health](https://phpackages.com/badges/maestroerror-html-strings-affixer/health.svg)](https://phpackages.com/packages/maestroerror-html-strings-affixer)
```

###  Alternatives

[wp-cli/wp-cli

WP-CLI framework

5.1k17.2M320](/packages/wp-cli-wp-cli)[consolidation/annotated-command

Initialize Symfony Console commands from annotated command class methods.

22569.8M19](/packages/consolidation-annotated-command)[seld/cli-prompt

Allows you to prompt for user input on the command line, and optionally hide the characters they type

24725.8M17](/packages/seld-cli-prompt)[illuminate/console

The Illuminate Console package.

12944.1M5.1k](/packages/illuminate-console)[php-tui/php-tui

Comprehensive TUI library heavily influenced by Ratatui

589747.0k6](/packages/php-tui-php-tui)[codedungeon/php-cli-colors

Liven up you PHP Console Apps with standard colors

10210.1M26](/packages/codedungeon-php-cli-colors)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
