* @package tao * @since 2.2 */ class tao_helpers_translation_JSFileWriter extends tao_helpers_translation_TranslationFileWriter { /** * Write a javascript AMD module that provides translations * for the target languages. * * @access public * @return mixed */ public function write() { $path = $this->getFilePath(); $strings = []; foreach ($this->getTranslationFile()->getTranslationUnits() as $tu) { if ($tu->getTarget() !== '') { $strings[$tu->getSource()] = $tu->getTarget(); } } $buffer = json_encode($strings, JSON_HEX_QUOT | JSON_HEX_APOS); if (!file_put_contents($path, $buffer)) { throw new tao_helpers_translation_TranslationException("An error occured while writing Javascript " . "translation file '${path}'."); } } }