Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Dec 26, 2022
1 parent 5fdbd90 commit 0dff2f6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"ext-json": "*",
"dereuromark/cakephp-queue": "^5.0",
"phpunit/phpunit": "^9.5",
"sepia/po-parser": "^6.0.1",
"yandex/translate-api": "dev-master",
"fig-r/psr2r-sniffer": "dev-master"
},
Expand Down
19 changes: 8 additions & 11 deletions src/Filesystem/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace Translate\Filesystem;

use Cake\Core\Configure;
use Sepia\FileHandler;
use Sepia\PoParser;
use Translate\Parser\PoParser;

class Dumper {

Expand All @@ -29,22 +28,20 @@ public function dump(array $translations, $domain, $lang, $folder = null) {
touch($file);
}

$content = $this->_compile($translations, $file);

return (bool)file_put_contents($file, $content);
return $this->_dump($translations, $file);
}

/**
* @param array<\Translate\Model\Entity\TranslateTerm> $translations $translations
* @param string $file
*
* @return string
* @return bool
*/
protected function _compile(array $translations, $file) {
protected function _dump(array $translations, $file) {
$max = Configure::read('Translate.plurals') ?: 2;
$pluralExpression = Configure::read('Translate.pluralExpression') ?: 'n != 1';

$po = new PoParser(new FileHandler($file));
$po = new PoParser();
$newHeaders = [
'"Project-Id-Version: \n"',
'"POT-Creation-Date: \n"',
Expand Down Expand Up @@ -80,15 +77,15 @@ protected function _compile(array $translations, $file) {
//$entry['flags'] = explode(',', $translation->translate_string->flags);
}

$po->setEntry($translation->translate_string->name, $entry);
$po->setEntries([$translation->translate_string->name => $entry]);
if ($translation->translate_string->plural !== null) {
//$po->setEntryPlural($translation->translate_string->name, $entry['msgstr']);
}
}

$content = $po->compile();
$po->write($file);

return $content;
return true;
}

}
6 changes: 3 additions & 3 deletions src/Lib/TranslationLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Cake\Filesystem\Folder;
use Cake\I18n\Parser\PoFileParser;
use Cake\Utility\Inflector;
use PoParser\Parser;
use Translate\Parser\PoParser;

class TranslationLib {

Expand Down Expand Up @@ -103,7 +103,7 @@ public function extractPotFile($domain, $dir = LOCALE) {
$content = [];

if (file_exists($file)) {
$poParser = new Parser();
$poParser = new PoParser();
$poParser->read($file);
$entries = $poParser->getEntriesAsArrays();

Expand All @@ -127,7 +127,7 @@ public function extractPoFile($domain, $lang, $dir = LOCALE) {
$content = [];

if (file_exists($file)) {
$poParser = new Parser();
$poParser = new PoParser();
$poParser->read($file);
$entries = $poParser->getEntriesAsArrays();

Expand Down
2 changes: 1 addition & 1 deletion src/Parser/PoParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public function clean($value) {
$value[$k] = $this->clean($v);
}
} else {
$value = preg_replace('/^\"|\"$/', '', $value);
$value = preg_replace('/^\"|\"$/', '', (string)$value);
$value = stripcslashes($value);
}

Expand Down
4 changes: 2 additions & 2 deletions templates/Admin/Translate/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</p>


<table style="text-align: top"><tr>
<table style="vertical-align: top"><tr>
<td>
<h3>Features</h3>

Expand Down Expand Up @@ -56,7 +56,7 @@
</p>

<?php
if (!empty($coverage)) {
if (!empty($coverage) && is_array($count)) {
?>

<?php echo $this->element('coverage_table', [])?>
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/Lib/TranslationLibTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function testGetPotFiles() {
$expected = [
'cake' => 'cake',
'default' => 'default',
'translate' => 'translate',
];
$this->assertSame($expected, $is);
}
Expand Down

0 comments on commit 0dff2f6

Please sign in to comment.