2 /***************************************************************
5 * (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
29 * Parser for XLIFF file.
33 * @author Dominique Feyer <dfeyer@reelpeek.net>
35 class t3lib_l10n_parser_Xliff
extends t3lib_l10n_parser_AbstractXml
{
38 * Returns array representation of XML data, starting from a root node.
40 * @param SimpleXMLElement $root A root node
41 * @return array An array representing the parsed XML file
43 protected function doParsingFromRoot(SimpleXMLElement
$root) {
44 $parsedData = array();
45 $bodyOfFileTag = $root->file
->body
;
47 foreach ($bodyOfFileTag->children() as $translationElement) {
48 if ($translationElement->getName() === 'trans-unit' && !isset($translationElement['restype'])) {
49 // If restype would be set, it could be metadata from Gettext to XLIFF conversion (and we don't need this data)
51 // @todo Support "approved" attribute
52 $parsedData[(string)$translationElement['id']][0] = array(
53 'source' => (string)$translationElement->source
,
54 'target' => (string)$translationElement->target
,
56 } elseif ($translationElement->getName() === 'group' && isset($translationElement['restype']) && (string)$translationElement['restype'] === 'x-gettext-plurals') {
57 // This is a translation with plural forms
58 $parsedTranslationElement = array();
60 foreach ($translationElement->children() as $translationPluralForm) {
61 if ($translationPluralForm->getName() === 'trans-unit') {
62 // When using plural forms, ID looks like this: 1[0], 1[1] etc
63 $formIndex = substr((string)$translationPluralForm['id'], strpos((string)$translationPluralForm['id'], '[') +
1, -1);
65 // @todo Support "approved" attribute
66 $parsedTranslationElement[(int)$formIndex] = array(
67 'source' => (string)$translationPluralForm->source
,
68 'target' => (string)$translationPluralForm->target
,
73 if (!empty($parsedTranslationElement)) {
74 if (isset($translationElement['id'])) {
75 $id = (string)$translationElement['id'];
77 $id = (string)($translationElement->{'trans-unit'}[0]['id']);
78 $id = substr($id, 0, strpos($id, '['));
81 $parsedData[$id] = $parsedTranslationElement;
91 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['t3lib/l10n/parser/class.t3lib_l10n_parser_xliff.php'])) {
92 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['t3lib/l10n/parser/class.t3lib_l10n_parser_xliff.php']);