Here's the situation we have language strings in our database mixed with html.
We need to be able to extract the language from between the tags, and present them to the translator for translation.
Then before we save the new translation content, replace the old language strings with new language strings.
Whatever this extraction tool is, it has to replace the original language with the new language and save it without modifying the tags already there.
I've tried DOM but it's a bit fickle and alters the HTML. Does anyone have a suggestion for a library that could be of use here?
Or a whole different approach, that'd be great.
Html Extraction For Language Translation
Moderator: General Moderators
Re: Html Extraction For Language Translation
Post what you've tried so far.
There are 10 types of people in this world, those who understand binary and those who don't
Re: Html Extraction For Language Translation
I've tried DOM.
I took the content, and built a recursive array of dom node values. The theory being that if I can wind it up like this consistently and wind it out with the same result, I should be able to replace them in order.
I took the content, and built a recursive array of dom node values. The theory being that if I can wind it up like this consistently and wind it out with the same result, I should be able to replace them in order.
Re: Html Extraction For Language Translation
I meant - PHP codeneophyte wrote:I've tried DOM.
I took the content, and built a recursive array of dom node values. The theory being that if I can wind it up like this consistently and wind it out with the same result, I should be able to replace them in order.
There are 10 types of people in this world, those who understand binary and those who don't
Re: Html Extraction For Language Translation
Code: Select all
protected function _parse(&$replacements = array(), $top_node = null)
{
$top_node = (empty($top_node))?$this->_get_root_node(): $top_node;
if ($top_node->hasChildNodes()) {
$subNodes = $top_node->childNodes;
foreach($subNodes as $subNode) {
if (($subNode->nodeType !=3) ||
(($subNode->nodeType ==3)
&& (strlen(trim($subNode->wholeText)) >=1)))
{
if ( $subNode->nodeName == '#text') {
if (!empty($replacements)) {
$subNode->replaceData(0, 1000000, array_shift($replacements));
}
$array[$subNode->nodeName][] = $subNode->nodeValue;
}
}
$array[] = $this->_parse($replacements, $subNode);
}
}
return (isset($array))?$array: null;
}
Re: Html Extraction For Language Translation
What's the input data so I can replay and debug?
There are 10 types of people in this world, those who understand binary and those who don't