[TASK] Add missing XCLASS to the t3lib_l10n_* classes
[Packages/TYPO3.CMS.git] / t3lib / l10n / parser / class.t3lib_l10n_parser_xliff.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2011 Dominique Feyer <dfeyer@reelpeek.net>
6 * All rights reserved
7 *
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.
13 *
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.
18 *
19 *
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.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Parser for XLIFF file.
30 *
31 * @package TYPO3
32 * @subpackage t3lib
33 * @author Dominique Feyer <dfeyer@reelpeek.net>
34 */
35 class t3lib_l10n_parser_Xliff extends t3lib_l10n_parser_AbstractXml {
36
37 /**
38 * Returns array representation of XML data, starting from a root node.
39 *
40 * @param SimpleXMLElement $root A root node
41 * @return array An array representing the parsed XML file
42 */
43 protected function doParsingFromRoot(SimpleXMLElement $root) {
44 $parsedData = array();
45 $bodyOfFileTag = $root->file->body;
46
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)
50
51 // @todo Support "approved" attribute
52 $parsedData[(string)$translationElement['id']][0] = array(
53 'source' => (string)$translationElement->source,
54 'target' => (string)$translationElement->target,
55 );
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();
59
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);
64
65 // @todo Support "approved" attribute
66 $parsedTranslationElement[(int)$formIndex] = array(
67 'source' => (string)$translationPluralForm->source,
68 'target' => (string)$translationPluralForm->target,
69 );
70 }
71 }
72
73 if (!empty($parsedTranslationElement)) {
74 if (isset($translationElement['id'])) {
75 $id = (string)$translationElement['id'];
76 } else {
77 $id = (string)($translationElement->{'trans-unit'}[0]['id']);
78 $id = substr($id, 0, strpos($id, '['));
79 }
80
81 $parsedData[$id] = $parsedTranslationElement;
82 }
83 }
84 }
85
86 return $parsedData;
87 }
88 }
89
90
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']);
93 }
94
95 ?>