How to maintain strict indentation when translating YAML configuration files (e.g., Kubernetes/Ansible documentation)?
“YAML relies on indentation (spaces) to represent hierarchy. Any indentation error can result in file parsing failure.”
Root Cause Analysis
Strict whitespace anchor protection
We not only translate the text, but also log the number of spaces before each line. After translation, the system enforces reinserting the translated content into the corresponding indentation level, ensuring the YAML syntax tree structure remains 100% correct.
Translation and Preservation of Comments
Comments in configuration files (the content following #) are critical for understanding the configuration. Users can opt to translate these comments to facilitate team comprehension, while leaving configuration keys unchanged.
Support for Multi-Document Streams
For single YAML files containing multiple documents (separated by `---`), the system identifies the delimiters and processes each section independently, preventing confusion between different modules’ content.
Final Solution Summary
Eliminate the operational nightmare of localizing technical configuration documents and ensure deployment scripts are globally applicable.