Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| tao_helpers_translation_JSFileWriter | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
| write | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2008-2010 (original work) Deutsche Institut für Internationale Pädagogische Forschung |
| 19 | * (under the project TAO-TRANSFER); |
| 20 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 21 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 22 | * 2013 (update and modification) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 23 | */ |
| 24 | |
| 25 | /** |
| 26 | * An implementation of TranslationFileWriter aiming at writing JavaScript |
| 27 | * files. |
| 28 | * |
| 29 | * @access public |
| 30 | * @author Jerome Bogaerts |
| 31 | * @author Bertrand Chevrier <bertrand@taotesting.com> |
| 32 | * @package tao |
| 33 | * @since 2.2 |
| 34 | |
| 35 | */ |
| 36 | class tao_helpers_translation_JSFileWriter extends tao_helpers_translation_TranslationFileWriter |
| 37 | { |
| 38 | /** |
| 39 | * Write a javascript AMD module that provides translations |
| 40 | * for the target languages. |
| 41 | * |
| 42 | * @access public |
| 43 | * @return mixed |
| 44 | */ |
| 45 | public function write() |
| 46 | { |
| 47 | |
| 48 | $path = $this->getFilePath(); |
| 49 | $strings = []; |
| 50 | |
| 51 | foreach ($this->getTranslationFile()->getTranslationUnits() as $tu) { |
| 52 | if ($tu->getTarget() !== '') { |
| 53 | $strings[$tu->getSource()] = $tu->getTarget(); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | $buffer = json_encode($strings, JSON_HEX_QUOT | JSON_HEX_APOS); |
| 58 | if (!file_put_contents($path, $buffer)) { |
| 59 | throw new tao_helpers_translation_TranslationException( |
| 60 | "An error occured while writing Javascript translation file '${path}'." |
| 61 | ); |
| 62 | } |
| 63 | } |
| 64 | } |