Skip to content

HSA for Laravel - helps make laravel project multilingual. Finds texts in HTML and replaces it with suffixed and prefixed string

License

Notifications You must be signed in to change notification settings

MaestroError/html-strings-affixer

Repository files navigation

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:
<p>Some nice string</p> -> <p>{{ __('Some nice string') }}</p>
But can be used in any file which contains html (".jsx", ".vue", ".twig") with same purpose. Of course, prefix and suffix are customizable

Navigation

Installation

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 ./vendor/bin/hsa and ./vendor/bin/hsawin for Windows

Linux/Unix

Step 1: Download
Download binary file 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

Download binary file or Zip. Get "hsa.exe" file in needed directory and run with ".\hsa.exe"

From source

If you have golang installed, you can clone this repo and run go install or go build for binary file

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: "#", "_", ">", "^", "*", "="
    • warnings: "%", "{", "(", "}", ")", "$", "'"
  • Ignore characters and warning characters are customizable from JSON config file ("ignore" and "warnings")

Config file

You need to create "affixer.json" file in directory, from where you will run html-strings-affixer. You can find an example 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

    // 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
    (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

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

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 arguments

  • -allowed="(string)" - allowed file types, separated by commas
  • -detailed - If passed, detailed report printed
  • -file="(string)" - Use this argument to run command only on one file
  • -folder="(string)" - Folder to scan
  • -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
  • -suffix="(string)" - New suffix for strings

Check command arguments

  • -allowed="(string)" - allowed file types, separated by commas
  • -file="(string)" - Use this argument to run command only on one file
  • -folder="(string)" - Folder to scan
  • -only="(string)" - Methods to use while parsing, separated by commas. Available: text, placeholder, alt, title, hashtag


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)

  • Add success message function in reporter
  • Make warnings table in reporter
  • Make TrimSpaces controllable as configuration from JSON and CLI
  • Add --expand option for detailed info in check command
  • Add --report option for detailed report (JSON) in check command
  • Next Release

  • Next Release

Upcoming

  • Write benchmarks for app
  • Make app available by npm (article)
  • 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)

Resources

About

HSA for Laravel - helps make laravel project multilingual. Finds texts in HTML and replaces it with suffixed and prefixed string

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •