Is it possible to directly translate strings in PHP files without breaking PHP tags and logic?

Core Issue Diagnosis

Many legacy websites hardcode text within PHP files, and manual extraction for translation carries significant risks.

Root Cause Analysis

AST Parsing

Systematically parse PHP code structure to accurately identify strings in `echo` and `print` statements as well as text in variable assignments, while ignoring control logic such as `if` or `foreach`.

HTML Mixed-Mode Handling

PHP files often contain HTML templates. We can simultaneously process HTML content outside PHP tags and strings within PHP tags to achieve dual parsing.

Escape Character Protection

When translating strings enclosed in single or double quotes, intelligently handle internal escape characters (such as `"` or `'`) to prevent syntax errors after translation that could result in a White Screen of Death.

Final Solution Summary

Provides an efficient solution for rapid internationalization of legacy systems without requiring code refactoring.