protected function TMGMTFileTestCase::createTranslationFile in Translation Management Tool 7
Creates a translated XLIFF file based on the replacement definition.
Parameters
string $source_file: Source file name.
$search: String to search in the source.
$replace: String to replace it with in the target.
$translated_file: Name of the file to write.
1 call to TMGMTFileTestCase::createTranslationFile()
- TMGMTFileTestCase::testXLIFFTextProcessing in translators/
file/ tmgmt_file.test - Test the content processing for XLIFF export and import.
File
- translators/
file/ tmgmt_file.test, line 499 - Test cases for the file translator module.
Class
- TMGMTFileTestCase
- Basic tests for the file translator.
Code
protected function createTranslationFile($source_file, $search, $replace, $translated_file) {
$xml_string = file_get_contents($source_file);
preg_match('/<source xml:lang="en">(.+)<\\/source>/s', $xml_string, $matches);
$target = str_replace($search, $replace, $matches[1]);
if ($replace) {
$this
->assertTrue(strpos($target, $replace) !== FALSE, 'String replaced in translation');
}
$translated_xml_string = str_replace('<target xml:lang="de"/>', '<target xml:lang="de">' . $target . '</target>', $xml_string);
file_put_contents($translated_file, $translated_xml_string);
}