Skip to content

Commit

Permalink
Merge pull request #100 from OPUS4/OPUSVIER-4220
Browse files Browse the repository at this point in the history
OPUSVIER-4220 Modifications for translations export/import.
  • Loading branch information
j3nsch authored Mar 28, 2020
2 parents cbccabc + 06ef4c6 commit ac99d0f
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 5 deletions.
48 changes: 46 additions & 2 deletions library/Opus/Translate/Dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @category Framework
* @package Opus
* @author Jens Schwidder <[email protected]>
* @copyright Copyright (c) 2018-2019, OPUS 4 development team
* @copyright Copyright (c) 2018-2020, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

Expand All @@ -43,8 +43,12 @@
* TODO is it necessary to support same key for multiple modules?
* TODO how to handle same key in default and module translations is not clear yet. What if a key needs to be edited in
* the administration? How to decide which module is meant?
*
* TODO merge getTranslations and getTranslationsByModule
* This is functionality for the management user interface. The translations are always needed with the module
* information.
*/
class Opus_Translate_Dao
class Opus_Translate_Dao implements \Opus\Translate\StorageInterface
{

public function remove($key, $module = null)
Expand Down Expand Up @@ -307,4 +311,44 @@ public function renameKey($key, $newKey, $module = 'default')

$database->commit();
}

public function getTranslationsWithModules()
{
$table = Opus_Db_TableGateway::getInstance('Opus_Db_Translations');

$select = $table->getAdapter()->select()
->from(['t' => 'translations'], ['keys.key', 'locale', 'value', 'keys.module'])
->join(['keys' => 'translationkeys'], 't.key_id = keys.id');

$rows = $table->getAdapter()->fetchAll($select);

$result = [];

foreach ($rows as $row) {
$key = $row['key'];
$locale = $row['locale'];
$value = $row['value'];
$module = $row['module'];

$result[$key]['module'] = $module;
$result[$key]['values'][$locale] = $value;
}

return $result;
}

/**
* @inheritDoc
*/
public function getModules()
{
$table = OPus_Db_TableGateway::getInstance('Opus_Db_Translations');

$select = $table->getAdapter()->select()
->from(['keys' => 'translationkeys'], ['keys.module'])->distinct();

$rows = $table->getAdapter()->fetchCol($select);

return $rows;
}
}
74 changes: 74 additions & 0 deletions tests/Opus/Translate/DaoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,78 @@ public function testRenameKeyDefaultOnly()
$translations = $dao->getTranslation('testkey1');
$this->assertEquals($data2, $translations);
}

public function testSetSpecialTranslation()
{
$dao = new Opus_Translate_Dao();

$data = [
'de' => 'Jump to',
'en' => 'Gehe zu'
];

$dao->setTranslation('admin-actionbox-goto-section', $data);

$translations = $dao->getTranslation('admin-actionbox-goto-section');

var_dump($translations);
}

public function testGetTranslationsWithModules()
{
$dao = new Opus_Translate_Dao();

$data = [
'de' => 'Deutsch',
'en' => 'Englisch'
];

$dao->setTranslation('testKey', $data, 'setup');

$translations = $dao->getTranslationsWithModules();

$this->assertNotNull($translations);
$this->assertArrayHasKey('testKey', $translations);

$testKey = $translations['testKey'];

$this->assertArrayHasKey('module', $testKey);
$this->assertEquals('setup', $testKey['module']);
$this->assertArrayHasKey('values', $testKey);
$this->assertEquals($data, $testKey['values']);
}

public function testGetModules()
{
$dao = new Opus_Translate_Dao();

$dao->setTranslation('testKey1', [
'en' => 'test key 1',
'de' => 'Testschlüssel 1'
]);

$dao->setTranslation('testKey2', [
'en' => 'test key 2',
'de' => 'Testschlüssel 2'
], 'home');

$dao->setTranslation('testKey3', [
'en' => 'test key 3',
'de' => 'Testschlüssel 3'
], 'admin');

$dao->setTranslation('testKey3', [
'en' => 'test key 4',
'de' => 'Testschlüssel 4'
], 'admin');

$modules = $dao->getModules();

$this->assertCount(3, $modules);
$this->assertEquals([
'default',
'home',
'admin'
], $modules);
}
}
3 changes: 0 additions & 3 deletions tests/config.ini.template
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ opusdb.params.admin.password = @db.admin.password@

db.debug = 1

opusdb.params.admin.name = @db.admin.name@
opusdb.params.admin.password = @db.admin.password@

;OPUS SETTINGS
workspacePath = APPLICATION_PATH "/tests/workspace"
resources.locale.default = 'de'
Expand Down

0 comments on commit ac99d0f

Please sign in to comment.