From 43accb53cd773b858e052df521aed2693db2c062 Mon Sep 17 00:00:00 2001 From: Metod Date: Tue, 7 Feb 2012 14:04:54 +0100 Subject: [PATCH 01/12] implemented xliff import --- Command/ImportCommand.php | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/Command/ImportCommand.php b/Command/ImportCommand.php index b0c4a65..4fe76f1 100644 --- a/Command/ImportCommand.php +++ b/Command/ImportCommand.php @@ -8,6 +8,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Finder\Finder; use Symfony\Component\Yaml\Parser; +use Symfony\Component\Translation\Loader\XliffFileLoader; /** * Command for importing translation files @@ -110,8 +111,36 @@ public function import($filename) } break; case 'xliff': - $this->output->writeln(" Skipping, not implemented"); - break; + $loader = new XliffFileLoader(); + $xliff = $loader->load($filename, $locale, $name); + + $data = $this->getContainer()->get('server_grove_translation_editor.storage_manager')->getCollection()->findOne(array('filename' => $filename)); + if (!$data) { + $data = array( + 'filename' => $filename, + 'locale' => $locale, + 'type' => $type, + 'entries' => array() + ); + } + + $this->output->writeln(" Found ".count($xliff->getDomains())." domains..."); + + $entries = $xliff->all(); + + foreach ($xliff->getDomains() as $domain) { + $this->output->writeln(" Processing '$domain' domain"); + $value = $entries[$domain]; + + $this->output->writeln(" Found ".count($value)." entries..."); + $data['entries'] = $value; + + if (!$this->input->getOption('dry-run')) { + $this->updateValue($data); + } + } + + break; } } From 73b50131ff7a95c04c9fec32c885dc5b0f1ff42d Mon Sep 17 00:00:00 2001 From: Metod Date: Tue, 7 Feb 2012 14:34:18 +0100 Subject: [PATCH 02/12] implemented xliff export --- Command/ExportCommand.php | 45 ++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/Command/ExportCommand.php b/Command/ExportCommand.php index c956e03..1a3d73e 100644 --- a/Command/ExportCommand.php +++ b/Command/ExportCommand.php @@ -84,14 +84,14 @@ public function export($filename) list($name, $locale, $type) = explode('.', $fname); + $data = $this->getContainer()->get('server_grove_translation_editor.storage_manager')->getCollection()->findOne(array('filename'=>$filename)); + if (!$data) { + $this->output->writeln("Could not find data for this locale"); + return; + } + switch($type) { case 'yml': - $data = $this->getContainer()->get('server_grove_translation_editor.storage_manager')->getCollection()->findOne(array('filename'=>$filename)); - if (!$data) { - $this->output->writeln("Could not find data for this locale"); - return; - } - foreach($data['entries'] as $key => $val) { if (empty($val)) { unset($data['entries'][$key]); @@ -101,16 +101,37 @@ public function export($filename) $dumper = new Dumper(); $result = $dumper->dump($data['entries'], 1); - $this->output->writeln(" Writing ".count($data['entries'])." entries to $filename"); - if (!$this->input->getOption('dry-run')) { - file_put_contents($filename, $result); - } - break; case 'xliff': - $this->output->writeln(" Skipping, not implemented"); + $xml = new \SimpleXMLElement(''); + + $xliff_file = $xml->addChild("file"); + $xliff_file->addAttribute("source-language", $locale); + $xliff_file->addAttribute("datatype", "plaintext"); + $xliff_file->addAttribute("original", "file.ext"); + + $body = $xliff_file->addChild('body'); + + $i = 1; + foreach($data['entries'] as $source => $target) { + if (empty($target)) { + continue; + } + + $unit = $body->addChild('trans-unit'); + $unit->addAttribute("id", ++$i); + $unit->addChild("source", $source); + $unit->addChild("target", $target); + } + + $xml = html_entity_decode($xml->asXML(), ENT_NOQUOTES, 'UTF-8'); break; } + + $this->output->writeln(" Writing ".count($data['entries'])." entries to $filename"); + if (!$this->input->getOption('dry-run')) { + file_put_contents($filename, $xml); + } } From 1c713768c4e8606e136f152da1a848eb3dc393c8 Mon Sep 17 00:00:00 2001 From: Metod Date: Tue, 7 Feb 2012 14:35:47 +0100 Subject: [PATCH 03/12] coding standard --- Command/ExportCommand.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Command/ExportCommand.php b/Command/ExportCommand.php index 1a3d73e..7f664ae 100644 --- a/Command/ExportCommand.php +++ b/Command/ExportCommand.php @@ -71,7 +71,7 @@ public function execute(InputInterface $input, OutputInterface $output) } $output->writeln(sprintf("Found %d files, exporting...", count($files))); - foreach($files as $filename) { + foreach ($files as $filename) { $this->export($filename); } @@ -92,7 +92,7 @@ public function export($filename) switch($type) { case 'yml': - foreach($data['entries'] as $key => $val) { + foreach ($data['entries'] as $key => $val) { if (empty($val)) { unset($data['entries'][$key]); } @@ -113,7 +113,7 @@ public function export($filename) $body = $xliff_file->addChild('body'); $i = 1; - foreach($data['entries'] as $source => $target) { + foreach ($data['entries'] as $source => $target) { if (empty($target)) { continue; } From dc3a76bed9702c31865b93e970dee8bddec240ca Mon Sep 17 00:00:00 2001 From: Metod Date: Tue, 7 Feb 2012 14:42:34 +0100 Subject: [PATCH 04/12] common code dependency --- Command/ImportCommand.php | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/Command/ImportCommand.php b/Command/ImportCommand.php index 4fe76f1..e0eb95f 100644 --- a/Command/ImportCommand.php +++ b/Command/ImportCommand.php @@ -87,22 +87,22 @@ public function import($filename) $this->setIndexes(); + $data = $this->getContainer()->get('server_grove_translation_editor.storage_manager')->getCollection()->findOne(array('filename'=>$filename)); + if (!$data) { + $data = array( + 'filename' => $filename, + 'locale' => $locale, + 'type' => $type, + 'entries' => array(), + ); + + } + switch($type) { case 'yml': $yaml = new Parser(); $value = $yaml->parse(file_get_contents($filename)); - $data = $this->getContainer()->get('server_grove_translation_editor.storage_manager')->getCollection()->findOne(array('filename'=>$filename)); - if (!$data) { - $data = array( - 'filename' => $filename, - 'locale' => $locale, - 'type' => $type, - 'entries' => array(), - ); - - } - $this->output->writeln(" Found ".count($value)." entries..."); $data['entries'] = $value; @@ -114,16 +114,6 @@ public function import($filename) $loader = new XliffFileLoader(); $xliff = $loader->load($filename, $locale, $name); - $data = $this->getContainer()->get('server_grove_translation_editor.storage_manager')->getCollection()->findOne(array('filename' => $filename)); - if (!$data) { - $data = array( - 'filename' => $filename, - 'locale' => $locale, - 'type' => $type, - 'entries' => array() - ); - } - $this->output->writeln(" Found ".count($xliff->getDomains())." domains..."); $entries = $xliff->all(); From 8b75869ed81d1d3b0d7ff5c187d96afdcb8681a7 Mon Sep 17 00:00:00 2001 From: Metod Date: Tue, 7 Feb 2012 15:06:54 +0100 Subject: [PATCH 05/12] start with id=1 --- Command/ExportCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/ExportCommand.php b/Command/ExportCommand.php index 7f664ae..4379115 100644 --- a/Command/ExportCommand.php +++ b/Command/ExportCommand.php @@ -112,7 +112,7 @@ public function export($filename) $body = $xliff_file->addChild('body'); - $i = 1; + $i = 0; foreach ($data['entries'] as $source => $target) { if (empty($target)) { continue; From e309231fd5f2e816c8bfe0f8e3de48338f63577f Mon Sep 17 00:00:00 2001 From: Metod Date: Tue, 7 Feb 2012 20:19:01 +0100 Subject: [PATCH 06/12] fixed broken yml export and exception if html tags are present in translations --- Command/ExportCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Command/ExportCommand.php b/Command/ExportCommand.php index 4379115..fed3335 100644 --- a/Command/ExportCommand.php +++ b/Command/ExportCommand.php @@ -124,13 +124,13 @@ public function export($filename) $unit->addChild("target", $target); } - $xml = html_entity_decode($xml->asXML(), ENT_NOQUOTES, 'UTF-8'); + $result = $xml->asXML(); break; } $this->output->writeln(" Writing ".count($data['entries'])." entries to $filename"); if (!$this->input->getOption('dry-run')) { - file_put_contents($filename, $xml); + file_put_contents($filename, $result); } } From 6a2c4b1d497f4850f21b22345bcca79bed07388d Mon Sep 17 00:00:00 2001 From: Metod Date: Sat, 11 Feb 2012 21:43:30 +0100 Subject: [PATCH 07/12] added --pretty-print option for formatted xml output --- Command/ExportCommand.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Command/ExportCommand.php b/Command/ExportCommand.php index fed3335..b625fa3 100644 --- a/Command/ExportCommand.php +++ b/Command/ExportCommand.php @@ -8,14 +8,12 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Finder\Finder; use Symfony\Component\Yaml\Dumper; + /** * Command for exporting translations into files */ - class ExportCommand extends Base { - - protected function configure() { parent::configure(); @@ -24,7 +22,8 @@ protected function configure() ->setName('locale:editor:export') ->setDescription('Export translations into files') ->addArgument('filename') - ->addOption("dry-run") + ->addOption('dry-run') + ->addOption('pretty-print') ; } @@ -105,7 +104,7 @@ public function export($filename) case 'xliff': $xml = new \SimpleXMLElement(''); - $xliff_file = $xml->addChild("file"); + $xliff_file = $xml->addChild("file"); $xliff_file->addAttribute("source-language", $locale); $xliff_file->addAttribute("datatype", "plaintext"); $xliff_file->addAttribute("original", "file.ext"); @@ -124,7 +123,17 @@ public function export($filename) $unit->addChild("target", $target); } - $result = $xml->asXML(); + $result = $xml->asXML(); + + if ($this->input->getOption('pretty-print')) { + $dom = new \DOMDocument('1.0'); + $dom->preserveWhiteSpace = false; + $dom->formatOutput = true; + $dom->loadXML($result); + + $result = $dom->saveXML(); + } + break; } @@ -133,8 +142,5 @@ public function export($filename) file_put_contents($filename, $result); } } - - } - From 74d16d5f384ded091bc7eb027f1315668beee254 Mon Sep 17 00:00:00 2001 From: Metod Date: Mon, 1 Apr 2013 10:52:25 +0300 Subject: [PATCH 08/12] Proper escaping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed Warning: SimpleXMLElement::addChild(): unterminated entity reference --- Command/ExportCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Command/ExportCommand.php b/Command/ExportCommand.php index b625fa3..c1e6d5f 100644 --- a/Command/ExportCommand.php +++ b/Command/ExportCommand.php @@ -119,8 +119,8 @@ public function export($filename) $unit = $body->addChild('trans-unit'); $unit->addAttribute("id", ++$i); - $unit->addChild("source", $source); - $unit->addChild("target", $target); + $unit->source = $source; + $Unit->target = $target; } $result = $xml->asXML(); From f94b2642c93fba83d388c1a5b0dccc7d35c36680 Mon Sep 17 00:00:00 2001 From: Metod Date: Sat, 13 Apr 2013 19:12:46 +0300 Subject: [PATCH 09/12] Typo fixed --- Command/ExportCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/ExportCommand.php b/Command/ExportCommand.php index c1e6d5f..a5819eb 100644 --- a/Command/ExportCommand.php +++ b/Command/ExportCommand.php @@ -120,7 +120,7 @@ public function export($filename) $unit = $body->addChild('trans-unit'); $unit->addAttribute("id", ++$i); $unit->source = $source; - $Unit->target = $target; + $unit->target = $target; } $result = $xml->asXML(); From 1d05cf8a56c9ffeda5188202a97d5e26935cd417 Mon Sep 17 00:00:00 2001 From: Metod Date: Sat, 15 Nov 2014 16:42:46 +0100 Subject: [PATCH 10/12] Use the new \MongoClient class Use the new \MongoClient class instead of the deprecated \Mongo --- MongoStorageManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MongoStorageManager.php b/MongoStorageManager.php index 76d5d5b..63ac6a6 100644 --- a/MongoStorageManager.php +++ b/MongoStorageManager.php @@ -18,7 +18,7 @@ public function __construct(ContainerInterface $container) function getMongo() { if (!$this->mongo) { - $this->mongo = new \Mongo($this->container->getParameter('translation_editor.mongodb')); + $this->mongo = new \MongoClient($this->container->getParameter('translation_editor.mongodb')); } if (!$this->mongo) { @@ -36,4 +36,4 @@ public function getCollection() { return $this->getDB()->selectCollection($this->container->getParameter('translation_editor.collection')); } -} \ No newline at end of file +} From 8a12d5db496791b19038378a5ab265a43eca723d Mon Sep 17 00:00:00 2001 From: Metod Date: Thu, 2 Jul 2015 19:45:51 +0200 Subject: [PATCH 11/12] symfony 3.0 compatibility --- Resources/config/routing.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index 788971b..b3144bb 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -1,15 +1,15 @@ sg_localeditor_list: - pattern: /translations/editor + path: /translations/editor defaults: { _controller: ServerGroveTranslationEditorBundle:Editor:list } sg_localeditor_update: - pattern: /translations/update + path: /translations/update defaults: { _controller: ServerGroveTranslationEditorBundle:Editor:update } sg_localeditor_add: - pattern: /translations/add + path: /translations/add defaults: { _controller: ServerGroveTranslationEditorBundle:Editor:add } sg_localeditor_remove: - pattern: /translations/remove + path: /translations/remove defaults: { _controller: ServerGroveTranslationEditorBundle:Editor:remove } From c3ca7d15701c077feb3355ce9b4d0c00caffebef Mon Sep 17 00:00:00 2001 From: Metod Date: Sun, 6 Dec 2015 13:17:35 +0100 Subject: [PATCH 12/12] search translation collections by locale name --- Command/ExportCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/ExportCommand.php b/Command/ExportCommand.php index a5819eb..52a9f13 100644 --- a/Command/ExportCommand.php +++ b/Command/ExportCommand.php @@ -83,7 +83,7 @@ public function export($filename) list($name, $locale, $type) = explode('.', $fname); - $data = $this->getContainer()->get('server_grove_translation_editor.storage_manager')->getCollection()->findOne(array('filename'=>$filename)); + $data = $this->getContainer()->get('server_grove_translation_editor.storage_manager')->getCollection()->findOne(array('locale'=>$locale)); if (!$data) { $this->output->writeln("Could not find data for this locale"); return;