protected function FileTranslatorTest::createTranslationFile in Translation Management Tool 8
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 FileTranslatorTest::createTranslationFile()
- FileTranslatorTest::testXLIFFTextProcessing in translators/
tmgmt_file/ tests/ src/ Functional/ FileTranslatorTest.php - Test the content processing for XLIFF export and import.
File
- translators/
tmgmt_file/ tests/ src/ Functional/ FileTranslatorTest.php, line 552
Class
- FileTranslatorTest
- Tests for the file translator.
Namespace
Drupal\Tests\tmgmt_file\FunctionalCode
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);
}