Reputation: 2158
I need to translate some of HTML page content. I have a lot of HTML documents as a list of files and a map with translations like this:
List<File> files
Map<String, String> translations
Only strings in specific tags (p, h1..h6, li) have to be translated. I want to end up with the same files like at the beginning but with replaced strings.
Two solutions that don't work:
Any solutions?
Upvotes: 0
Views: 406
Reputation: 4089
You pretty much have to use a proper html parser (which fixes the dom structure), because otherwise there's no way to tell where an element starts and where it ends. There are all sorts of special cases and different types of broken html and if you want to handle them all, you are basically implementing a full html parser.
The only other way I can think of (and which is often used) is to use placeholders in the original files, such as <h1>${title}</h1> <p>${introduction}</p>
etc, and find and replace them directly, but I guess that would require a lot of work to change the files if you don't already have them in this form.
Upvotes: 1