Skip to content

GalahadXVI/laravel-translation-strings-to-keys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Laravel Translation Key Updater

This quickly hacked up Python script scans a specified PHP or Blade file to replace hardcoded translation strings within __() calls with keys. It then updates a specified translation file (in Laravel's /lang format) to include the detected strings as key-value pairs. The script is interactive, allowing you to customize keys or accept defaults based on the translation text.

Features

  • Finds hardcoded strings within __() calls.
  • Prompts for each detected string, suggesting a default key derived from the first four words. You can customize the key or press Enter to accept the default.
  • Adds new key-value pairs to the specified translation file without removing existing entries.
  • Preserves HTML tags, attributes, and placeholders like :name or :quantity.

Requirements

  • Python 3
  • Laravel Project with a Translations Directory: Laravel’s lang directory.

Usage

python move-translation-strings-to-keys.py <input_file> <translation_file>

Example:

python move-translation-strings-to-keys.py resources/views/profile/index/partials/hero/core.blade.php lang/en/profile.php

About

Automatically convert translation strings to keys

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages