Skip to content
Browse files

implement translations interfaces

  • Loading branch information...
1 parent b19e0c8 commit 42d0405db2611435382ee3259ab4170a0285bb2a @skie skie committed Sep 29, 2011
View
166 controllers/translations_controller.php
@@ -0,0 +1,166 @@
+<?php
+class TranslationsController extends AppController {
+/**
+ * Controller name
+ *
+ * @var string
+ * @access public
+ */
+ public $name = 'Translations';
+
+/**
+ * Helpers
+ *
+ * @var array
+ * @access public
+ */
+ public $helpers = array('Html', 'Form');
+
+/**
+ * Components
+ *
+ * @var array
+ * @access public
+ */
+ public $components = array('Search.Prg');
+
+/**
+ * Fields to preset in search forms
+ *
+ * @var array
+ * @see Search.PrgComponent
+ */
+ public $presetVars = array(
+ array('field' => 'locale', 'type' => 'value'),
+ array('field' => 'model', 'type' => 'value'),
+ array('field' => 'field', 'type' => 'value'),
+ array('field' => 'content', 'type' => 'value'),
+ );
+
+ public $uses = array('I18n.Translation');
+
+/**
+ * Admin index for translation.
+ *
+ * @access public
+ */
+ public function admin_index() {
+ $this->Prg->commonProcess();
+ $this->paginate = array(
+ 'search',
+ 'conditions' => $this->Translation->parseCriteria($this->passedArgs));
+
+ $this->set('translations', $this->paginate());
+ }
+
+/**
+ * Admin view for translation.
+ *
+ * @param string $id, translation id
+ * @access public
+ */
+ public function admin_view($id = null) {
+ try {
+ $translation = $this->Translation->view($id);
+ } catch (OutOfBoundsException $e) {
+ $this->Session->setFlash($e->getMessage());
+ $this->redirect(array('action' => 'index'));
+ }
+ $this->set(compact('translation'));
+ }
+
+/**
+ * Admin add for translation.
+ *
+ * @access public
+ */
+ public function admin_add() {
+ try {
+ $result = $this->Translation->add($this->data);
+ if ($result === true) {
+ $this->Session->setFlash(__('The translation has been saved', true));
+ $this->redirect(array('action' => 'index'));
+ }
+ } catch (OutOfBoundsException $e) {
+ $this->Session->setFlash($e->getMessage());
+ } catch (Exception $e) {
+ $this->Session->setFlash($e->getMessage());
+ $this->redirect(array('action' => 'index'));
+ }
+
+ }
+
+/**
+ * Admin edit for translation.
+ *
+ * @param string $id, translation id
+ * @access public
+ */
+ public function admin_edit($id = null) {
+ try {
+ $result = $this->Translation->edit($id, $this->data);
+ if ($result === true) {
+ $this->Session->setFlash(__('Translation saved', true));
+ $this->redirect(array('action' => 'view', $this->Translation->data['Translation']['id']));
+
+ } else {
+ $this->data = $result;
+ }
+ } catch (OutOfBoundsException $e) {
+ $this->Session->setFlash($e->getMessage());
+ $this->redirect('/');
+ }
+
+ }
+
+/**
+ * Admin edit for translation.
+ *
+ * @param string $id, translation id
+ * @access public
+ */
+ public function admin_edit_multi($model, $foreignKey) {
+ debug($this->data);
+ $locales = Configure::read('Config.locales.available');
+ $this->set(compact('model', 'foreignKey', 'locales'));
+ try {
+ $result = $this->Translation->edit_multi($model, $foreignKey, $this->data);
+ if ($result === true) {
+ $this->Session->setFlash(__('Translation saved', true));
+// $this->redirect(array('action' => 'view', $this->Translation->data['Translation']['id']));
+
+ } else {
+ $this->set('translations', $result);
+ $this->data = $result;
+ }
+ } catch (OutOfBoundsException $e) {
+ $this->Session->setFlash($e->getMessage());
+// $this->redirect('/');
+ }
+
+ }
+
+/**
+ * Admin delete for translation.
+ *
+ * @param string $id, translation id
+ * @access public
+ */
+ public function admin_delete($id = null) {
+ try {
+ $result = $this->Translation->validateAndDelete($id, $this->data);
+ if ($result === true) {
+ $this->Session->setFlash(__('Translation deleted', true));
+ $this->redirect(array('action' => 'index'));
+ }
+ } catch (Exception $e) {
+ $this->Session->setFlash($e->getMessage());
+ $this->redirect(array('action' => 'index'));
+ }
+ if (!empty($this->Translation->data['translation'])) {
+ $this->set('translation', $this->Translation->data['translation']);
+ }
+ }
+
+}
+?>
View
267 models/translation.php
@@ -0,0 +1,267 @@
+<?php
+class Translation extends AppModel {
+
+/**
+ * Name
+ *
+ * @var string $name
+ * @access public
+ */
+ public $name = 'Translation';
+
+/**
+ * model table
+ *
+ * @var string $name
+ * @access public
+ */
+ public $useTable = 'i18n';
+
+/**
+ * Validation parameters - initialized in constructor
+ *
+ * @var array
+ * @access public
+ */
+ public $validate = array();
+
+/**
+ * Filter args attribute to be used by the Searchable behavior
+ *
+ * @var array
+ * @access public
+ */
+ public $filterArgs = array(
+ array('name' => 'locale', 'type' => 'like'),
+ array('name' => 'model', 'type' => 'like'),
+ array('name' => 'field', 'type' => 'like'),
+ array('name' => 'content', 'type' => 'like')
+ );
+
+/**
+ * Behaviors
+ *
+ * @var array
+ */
+ public $actsAs = array(
+ 'Search.Searchable');
+
+/**
+ * List of valid finder method options, supplied as the first parameter to find().
+ *
+ * @var array
+ */
+ public $_findMethods = array('search' => true);
+
+/**
+ * Constructor
+ *
+ * @param mixed $id Model ID
+ * @param string $table Table name
+ * @param string $ds Datasource
+ * @access public
+ */
+ public function __construct($id = false, $table = null, $ds = null) {
+ parent::__construct($id, $table, $ds);
+ $this->validate = array(
+ 'locale' => array(
+ 'notempty' => array('rule' => array('notempty'), 'required' => true, 'allowEmpty' => false, 'message' => __('Please enter a Locale', true))),
+ 'model' => array(
+ 'notempty' => array('rule' => array('notempty'), 'required' => true, 'allowEmpty' => false, 'message' => __('Please enter a Model', true))),
+ 'foreign_key' => array(
+ 'uuid' => array('rule' => array('uuid'), 'required' => true, 'allowEmpty' => false, 'message' => __('Please enter a Foreign Key', true))),
+ 'field' => array(
+ 'notempty' => array('rule' => array('notempty'), 'required' => true, 'allowEmpty' => false, 'message' => __('Please enter a Field', true))),
+ );
+ }
+
+/**
+ * Adds a new record to the database
+ *
+ * @param array post data, should be Contoller->data
+ * @return array
+ * @access public
+ */
+ public function add($data = null) {
+ if (!empty($data)) {
+ $this->create();
+ $result = $this->save($data);
+ if ($result !== false) {
+ $this->data = array_merge($data, $result);
+ return true;
+ } else {
+ throw new OutOfBoundsException(__('Could not save the translation, please check your inputs.', true));
+ }
+ return $return;
+ }
+ }
+
+/**
+ * Edits an existing Translation.
+ *
+ * @param string $id, translation id
+ * @param array $data, controller post data usually $this->data
+ * @return mixed True on successfully save else post data as array
+ * @throws OutOfBoundsException If the element does not exists
+ * @access public
+ */
+ public function edit($id = null, $data = null) {
+ $translation = $this->find('first', array(
+ 'conditions' => array(
+ "{$this->alias}.{$this->primaryKey}" => $id,
+ )));
+
+ if (empty($translation)) {
+ throw new OutOfBoundsException(__('Invalid Translation', true));
+ }
+ $this->set($translation);
+
+ if (!empty($data)) {
+ $this->set($data);
+ $result = $this->save(null, true);
+ if ($result) {
+ $this->data = $result;
+ return true;
+ } else {
+ return $data;
+ }
+ } else {
+ return $translation;
+ }
+ }
+
+/**
+ * Edits an existing Translation.
+ *
+ * @param string $id, translation id
+ * @param array $data, controller post data usually $this->data
+ * @return mixed True on successfully save else post data as array
+ * @throws OutOfBoundsException If the element does not exists
+ * @access public
+ */
+ public function edit_multi($model, $foreignKey, $data = null) {
+ $translations = $this->find('all', array(
+ 'order' => array('locale'),
+ 'conditions' => array(
+ "{$this->alias}.model" => $model,
+ "{$this->alias}.foreign_key" => $foreignKey,
+ )));
+
+ if (empty($translations)) {
+ throw new OutOfBoundsException(__('Invalid Translation', true));
+ }
+
+ // @@todo code here
+
+ // $this->set($translation);
+
+ if (!empty($data[$this->alias])) {
+ foreach ($data[$this->alias] as $locale => $fields) {
+ foreach ($fields as $field => $_data) {
+ if (!empty($_data['id'])) {
+ $record = $this->read(null, $_data['id']);
+ $record[$this->alias]['content'] = $_data['content'];
+ $this->save($record);
+ } else {
+ $record = array('Translation' => array(
+ 'model' => $model,
+ 'foreign_key' => $foreignKey,
+ 'locale' => $locale,
+ 'field' => $field,
+ 'content' => $_data['content']));
+ $this->create($record);
+ $this->save($record);
+ }
+ }
+ }
+ return true;
+ } else {
+ return $translations;
+ }
+ }
+
+/**
+ * Returns the record of a Translation.
+ *
+ * @param string $id, translation id.
+ * @return array
+ * @throws OutOfBoundsException If the element does not exists
+ * @access public
+ */
+ public function view($id = null) {
+ $translation = $this->find('first', array(
+ 'conditions' => array(
+ "{$this->alias}.{$this->primaryKey}" => $id)));
+
+ if (empty($translation)) {
+ throw new OutOfBoundsException(__('Invalid Translation', true));
+ }
+
+ return $translation;
+ }
+
+/**
+ * Validates the deletion
+ *
+ * @param string $id, translation id
+ * @param array $data, controller post data usually $this->data
+ * @return boolean True on success
+ * @throws OutOfBoundsException If the element does not exists
+ * @access public
+ */
+ public function validateAndDelete($id = null, $data = array()) {
+ $translation = $this->find('first', array(
+ 'conditions' => array(
+ "{$this->alias}.{$this->primaryKey}" => $id,
+ )));
+
+ if (empty($translation)) {
+ throw new OutOfBoundsException(__('Invalid Translation', true));
+ }
+
+ $this->data['translation'] = $translation;
+ if (!empty($data)) {
+ $data['Translation']['id'] = $id;
+ $tmp = $this->validate;
+ $this->validate = array(
+ 'id' => array('rule' => 'notEmpty'),
+ 'confirm' => array('rule' => '[1]'));
+
+ $this->set($data);
+ if ($this->validates()) {
+ if ($this->delete($data['Translation']['id'])) {
+ return true;
+ }
+ }
+ $this->validate = $tmp;
+ throw new Exception(__('You need to confirm to delete this Translation', true));
+ }
+ }
+
+/**
+ * Perform search request
+ *
+ * @param string $state
+ * @param array $query
+ * @param array $results
+ * @return array
+ * @access public
+ */
+ public function _findSearch($state, $query, $results = array()) {
+ if ($state == 'before') {
+ //$query = Set::merge($defaults, $query);
+ if (!empty($query['operation']) && $query['operation'] === 'count') {
+ unset($query['limit']);
+ $query = $this->_findCount('before', $query, $results);
+ }
+ return $query;
+
+ } elseif ($state == 'after') {
+ if (isset($query['operation']) && $query['operation'] == 'count') {
+ $results = $this->_findCount('after', $query, $results);
+ }
+ return $results;
+ }
+ }
+
+}
View
163 tests/cases/controllers/translations_controller.test.php
@@ -0,0 +1,163 @@
+<?php
+/* Translations Test cases generated on: 2011-09-28 12:09:58 : 1317214078*/
+App::import('Controller', 'I18n.Translations');
+
+App::import('Lib', 'Templates.AppTestCase');
+class TranslationsControllerTestCase extends AppTestCase {
+/**
+ * Autoload entrypoint for fixtures dependecy solver
+ *
+ * @var string
+ * @access public
+ */
+ public $plugin = 'i18n';
+
+/**
+ * Test to run for the test case (e.g array('testFind', 'testView'))
+ * If this attribute is not empty only the tests from the list will be executed
+ *
+ * @var array
+ * @access protected
+ */
+ protected $_testsToRun = array();
+
+/**
+ * Start Test callback
+ *
+ * @param string $method
+ * @return void
+ * @access public
+ */
+ public function startTest($method) {
+ parent::startTest($method);
+ $this->Translations = AppMock::getTestController('TranslationsController');
+ $this->Translations->constructClasses();
+ $this->Translations->params = array(
+ 'named' => array(),
+ 'pass' => array(),
+ 'url' => array());
+ $fixture = new I18nFixture();
+ $this->record = array('Translation' => $fixture->records[0]);
+ }
+
+/**
+ * End Test callback
+ *
+ * @param string $method
+ * @return void
+ * @access public
+ */
+ public function endTest($method) {
+ parent::endTest($method);
+ unset($this->Translations);
+ ClassRegistry::flush();
+ }
+
+/**
+ * Convenience method to assert Flash messages
+ *
+ * @return void
+ * @access public
+ */
+ public function assertFlash($message) {
+ $flash = $this->Translations->Session->read('Message.flash');
+ $this->assertEqual($flash['message'], $message);
+ $this->Translations->Session->delete('Message.flash');
+ }
+
+/**
+ * Test object instances
+ *
+ * @return void
+ * @access public
+ */
+ public function testInstance() {
+ $this->assertIsA($this->Translations, 'TranslationsController');
+ //$this->assertIsA($this->Translations->Translation, 'Translation');
+ }
+
+
+/**
+ * testAdminIndex
+ *
+ * @return void
+ * @access public
+ */
+ public function testAdminIndex() {
+ $this->Translations->admin_index();
+ $this->assertTrue(!empty($this->Translations->viewVars['translations']));
+ }
+
+/**
+ * testAdminAdd
+ *
+ * @return void
+ * @access public
+ */
+ public function testAdminAdd() {
+ $this->Translations->data = $this->record;
+ $this->Translations->data['Translation']['foreign_key'] = 'article-2';
+ unset($this->Translations->data['Translation']['id']);
+ $this->Translations->admin_add();
+ $this->Translations->expectRedirect(array('action' => 'index'));
+ $this->assertFlash('The translation has been saved');
+ $this->Translations->expectExactRedirectCount();
+ }
+
+/**
+ * testAdminEdit
+ *
+ * @return void
+ * @access public
+ */
+ public function testAdminEdit() {
+ $this->Translations->admin_edit('translation-1');
+ $this->assertEqual($this->Translations->data['Translation'], $this->record['Translation']);
+
+ $this->Translations->data = $this->record;
+ $this->Translations->admin_edit('translation-1');
+ $this->Translations->expectRedirect(array('action' => 'view', 1));
+ $this->assertFlash('Translation saved');
+ $this->Translations->expectExactRedirectCount();
+ }
+
+/**
+ * testAdminView
+ *
+ * @return void
+ * @access public
+ */
+ public function testAdminView() {
+ $this->Translations->admin_view('translation-1');
+ $this->assertTrue(!empty($this->Translations->viewVars['translation']));
+
+ $this->Translations->admin_view('WRONG-ID');
+ $this->Translations->expectRedirect(array('action' => 'index'));
+ $this->assertFlash('Invalid Translation');
+ $this->Translations->expectExactRedirectCount();
+ }
+
+/**
+ * testAdminDelete
+ *
+ * @return void
+ * @access public
+ */
+ public function testAdminDelete() {
+ $this->Translations->admin_delete('WRONG-ID');
+ $this->Translations->expectRedirect(array('action' => 'index'));
+ $this->assertFlash('Invalid Translation');
+
+ $this->Translations->admin_delete('translation-1');
+ $this->assertTrue(!empty($this->Translations->viewVars['translation']));
+
+ $this->Translations->data = array('Translation' => array('confirmed' => 1));
+ $this->Translations->admin_delete('translation-1');
+ $this->Translations->expectRedirect(array('action' => 'index'));
+ $this->assertFlash('Translation deleted');
+ $this->Translations->expectExactRedirectCount();
+ }
+
+
+
+}
View
177 tests/cases/models/translation.test.php
@@ -0,0 +1,177 @@
+<?php
+/* Translation Test cases generated on: 2011-09-28 12:09:49 : 1317214069*/
+App::import('Model', 'Translation');
+
+App::import('Lib', 'Templates.AppTestCase');
+class TranslationTestCase extends AppTestCase {
+/**
+ * Autoload entrypoint for fixtures dependecy solver
+ *
+ * @var string
+ * @access public
+ */
+ public $plugin = 'i18n';
+
+/**
+ * Test to run for the test case (e.g array('testFind', 'testView'))
+ * If this attribute is not empty only the tests from the list will be executed
+ *
+ * @var array
+ * @access protected
+ */
+ protected $_testsToRun = array();
+
+/**
+ * Start Test callback
+ *
+ * @param string $method
+ * @return void
+ * @access public
+ */
+ public function startTest($method) {
+ parent::startTest($method);
+ $this->Translation = AppMock::getTestModel('I18n.Translation');
+ $fixture = new I18nFixture();
+ $this->record = array('Translation' => $fixture->records[0]);
+ }
+
+/**
+ * End Test callback
+ *
+ * @param string $method
+ * @return void
+ * @access public
+ */
+ public function endTest($method) {
+ parent::endTest($method);
+ unset($this->Translation);
+ ClassRegistry::flush();
+ }
+
+/**
+ * Test validation rules
+ *
+ * @return void
+ * @access public
+ */
+ public function testValidation() {
+ $this->assertValid($this->Translation, $this->record);
+
+ // Test mandatory fields
+ $data = array('Translation' => array('id' => 'new-id'));
+ $expectedErrors = array('locale', 'model', 'foreign_key', 'field'); // TODO Update me with mandatory fields
+ $this->assertValidationErrors($this->Translation, $data, $expectedErrors);
+ }
+
+/**
+ * Test adding a Translation
+ *
+ * @return void
+ * @access public
+ */
+ public function testAdd() {
+ $data = $this->record;
+ unset($data['Translation']['id']);
+ $data['Translation']['foreign_key'] = 'article-2';
+ $result = $this->Translation->add($data);
+ $this->assertTrue($result);
+
+ try {
+ $data = $this->record;
+ unset($data['Translation']['id']);
+ unset($data['Translation']['field']);
+ $result = $this->Translation->add($data);
+ $this->fail('No exception');
+ } catch (OutOfBoundsException $e) {
+ $this->pass('Correct exception thrown');
+ }
+
+ }
+
+/**
+ * Test editing a Translation
+ *
+ * @return void
+ * @access public
+ */
+ public function testEdit() {
+ $result = $this->Translation->edit('translation-1', null);
+
+ $expected = $this->Translation->read(null, 'translation-1');
+ $this->assertEqual($result['Translation'], $expected['Translation']);
+
+ // put invalidated data here
+ $data = $this->record;
+ $data['Translation']['field'] = null;
+
+ $result = $this->Translation->edit('translation-1', $data);
+ $this->assertEqual($result, $data);
+
+ $data = $this->record;
+
+ $result = $this->Translation->edit('translation-1', $data);
+ $this->assertTrue($result);
+
+ $result = $this->Translation->read(null, 'translation-1');
+
+ // put record specific asserts here for example
+ // $this->assertEqual($result['Translation']['title'], $data['Translation']['title']);
+
+ try {
+ $this->Translation->edit('wrong_id', $data);
+ $this->fail('No exception');
+ } catch (OutOfBoundsException $e) {
+ $this->pass('Correct exception thrown');
+ }
+ }
+
+/**
+ * Test viewing a single Translation
+ *
+ * @return void
+ * @access public
+ */
+ public function testView() {
+ $result = $this->Translation->view('translation-1');
+ $this->assertTrue(isset($result['Translation']));
+ $this->assertEqual($result['Translation']['id'], 'translation-1');
+
+ try {
+ $result = $this->Translation->view('wrong_id');
+ $this->fail('No exception on wrong id');
+ } catch (OutOfBoundsException $e) {
+ $this->pass('Correct exception thrown');
+ }
+ }
+
+/**
+ * Test ValidateAndDelete method for a Translation
+ *
+ * @return void
+ * @access public
+ */
+ public function testValidateAndDelete() {
+ try {
+ $postData = array();
+ $this->Translation->validateAndDelete('invalidTranslationId', $postData);
+ } catch (OutOfBoundsException $e) {
+ $this->assertEqual($e->getMessage(), 'Invalid Translation');
+ }
+ try {
+ $postData = array(
+ 'Translation' => array(
+ 'confirm' => 0));
+ $result = $this->Translation->validateAndDelete('translation-1', $postData);
+ } catch (Exception $e) {
+ $this->assertEqual($e->getMessage(), 'You need to confirm to delete this Translation');
+ }
+
+ $postData = array(
+ 'Translation' => array(
+ 'confirm' => 1));
+ $result = $this->Translation->validateAndDelete('translation-1', $postData);
+ $this->assertTrue($result);
+ }
+
+}
+?>
View
7 tests/config/fixtures.php
@@ -0,0 +1,7 @@
+<?php
+ // Please order me by alphabetical order
+ $config = array(
+ 'plugin.i18n.i18n',
+ 'plugin.i18n.article',
+ //'plugin.i18n.translation',
+ );
View
61 tests/fixtures/i18n_fixture.php
@@ -0,0 +1,61 @@
+<?php
+/* Translation Fixture generated on: 2011-09-28 12:09:49 : 1317214069 */
+class I18nFixture extends CakeTestFixture {
+/**
+ * Name
+ *
+ * @var string
+ * @access public
+ */
+ public $name = 'I18n';
+
+/**
+ * Name
+ *
+ * @var string
+ * @access public
+ */
+ public $table = 'I18n';
+
+/**
+ * Fields
+ *
+ * @var array
+ * @access public
+ */
+ public $fields = array(
+ 'id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'key' => 'primary'),
+ 'locale' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 3, 'key' => 'index'),
+ 'model' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 64, 'key' => 'index'),
+ 'foreign_key' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36),
+ 'field' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 64),
+ 'content' => array('type' => 'text', 'null' => true, 'default' => NULL),
+ 'indexes' => array(
+ 'PRIMARY' => array('column' => 'id', 'unique' => 1),
+ 'I18N_LOCALE_FIELD' => array('column' => array('locale', 'model', 'foreign_key', 'field'), 'unique' => 1),
+ 'I18N_LOCALE_ROW' => array('column' => array('locale', 'model', 'foreign_key'), 'unique' => 0),
+ 'I18N_LOCALE_MODEL' => array('column' => array('locale', 'model'), 'unique' => 0), 'I18N_FIELD' => array('column' => array('model', 'foreign_key', 'field'), 'unique' => 0),
+ 'I18N_ROW' => array('column' => array('model', 'foreign_key'), 'unique' => 0)
+ ),
+ 'tableParameters' => array(
+ 'engine' => 'MyISAM')
+ );
+
+/**
+ * Records
+ *
+ * @var array
+ * @access public
+ */
+ public $records = array(
+ array(
+ 'id' => 'translation-1',
+ 'locale' => 'eng',
+ 'model' => 'Article',
+ 'foreign_key' => 'article-1',
+ 'field' => 'title',
+ 'content' => 'sample content.'
+ ),
+ );
+
+}
View
53 tests/fixtures/translation_fixture.php
@@ -0,0 +1,53 @@
+<?php
+/* Translation Fixture generated on: 2011-09-28 12:09:49 : 1317214069 */
+class TranslationFixture extends CakeTestFixture {
+/**
+ * Name
+ *
+ * @var string
+ * @access public
+ */
+ public $name = 'Translation';
+
+/**
+ * Fields
+ *
+ * @var array
+ * @access public
+ */
+ public $fields = array(
+ 'id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'key' => 'primary', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
+ 'locale' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 3, 'key' => 'index', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
+ 'model' => array('type' => 'string', 'null' => false, 'default' => NULL, 'key' => 'index', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
+ 'foreign_key' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
+ 'field' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 64, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
+ 'content' => array('type' => 'text', 'null' => true, 'default' => NULL, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
+ 'indexes' => array(
+ 'PRIMARY' => array('column' => 'id', 'unique' => 1),
+ 'I18N_LOCALE_FIELD' => array('column' => array('locale', 'model', 'foreign_key', 'field'), 'unique' => 1),
+ 'I18N_LOCALE_ROW' => array('column' => array('locale', 'model', 'foreign_key'), 'unique' => 0),
+ 'I18N_LOCALE_MODEL' => array('column' => array('locale', 'model'), 'unique' => 0), 'I18N_FIELD' => array('column' => array('model', 'foreign_key', 'field'), 'unique' => 0),
+ 'I18N_ROW' => array('column' => array('model', 'foreign_key'), 'unique' => 0)
+ ),
+ 'tableParameters' => array(
+ 'charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'MyISAM')
+ );
+
+/**
+ * Records
+ *
+ * @var array
+ * @access public
+ */
+ public $records = array(
+ array(
+ 'id' => 'translate-1',
+ 'locale' => 'eng',
+ 'model' => 'Article',
+ 'foreign_key' => 'article-1',
+ 'field' => 'title',
+ 'content' => 'sample content.'
+ ),
+ );
+
+}
View
19 views/translations/admin_add.ctp
@@ -0,0 +1,19 @@
+<div class="translations form">
+<?php echo $this->Form->create('Translation', array('url' => array('action' => 'add')));?>
+ <fieldset>
+ <legend><?php __('Admin Add Translation');?></legend>
+ <?php
+ echo $this->Form->input('locale');
+ echo $this->Form->input('model');
+ echo $this->Form->input('foreign_key');
+ echo $this->Form->input('field');
+ echo $this->Form->input('content');
+ ?>
+ </fieldset>
+<?php echo $this->Form->end('Submit');?>
+</div>
+<div class="actions">
+ <ul>
+ <li><?php echo $this->Html->link(__('List Translations', true), array('action' => 'index'));?></li>
+ </ul>
+</div>
View
16 views/translations/admin_delete.ctp
@@ -0,0 +1,16 @@
+<h2><?php echo sprintf(__('Delete Translation "%s"?', true), $translation['Translation']['title']); ?></h2>
+<p>
+ <?php __('Be aware that your Translation and all associated data will be deleted if you confirm!'); ?>
+</p>
+<?php
+ echo $this->Form->create('Translation', array(
+ 'url' => array(
+ 'action' => 'delete',
+ $translation['Translation']['id'])));
+ echo $form->input('confirm', array(
+ 'label' => __('Confirm', true),
+ 'type' => 'checkbox',
+ 'error' => __('You have to confirm.', true)));
+ echo $form->submit(__('Continue', true));
+ echo $form->end();
+?>
View
21 views/translations/admin_edit.ctp
@@ -0,0 +1,21 @@
+<div class="translations form">
+<?php echo $this->Form->create('Translation', array('url' => array('action' => 'edit')));?>
+ <fieldset>
+ <legend><?php __('Admin Edit Translation');?></legend>
+ <?php
+ echo $this->Form->input('id');
+ echo $this->Form->input('locale');
+ echo $this->Form->input('model');
+ echo $this->Form->input('foreign_key');
+ echo $this->Form->input('field');
+ echo $this->Form->input('content');
+ ?>
+ </fieldset>
+<?php echo $this->Form->end('Submit');?>
+</div>
+<div class="actions">
+ <ul>
+ <li><?php echo $this->Html->link(__('Delete', true), array('action' => 'delete', $this->Form->value('Translation.id'))); ?></li>
+ <li><?php echo $this->Html->link(__('List Translations', true), array('action' => 'index'));?></li>
+ </ul>
+</div>
View
28 views/translations/admin_edit_multi.ctp
@@ -0,0 +1,28 @@
+<div class="translations form">
+<?php echo $this->Form->create('Translation', array('url' => array('action' => 'edit_multi', $model, $foreignKey)));?>
+ <fieldset>
+ <legend><?php __('Admin Edit Translation');?></legend>
+ <?php
+ echo '<h3>' . $model . '</h3>';
+
+ foreach ($translations as $translation) {
+ $field = $translation['Translation']['field'];
+ $locale = $translation['Translation']['locale'];
+ $id = $translation['Translation']['id'];
+ echo $this->Form->hidden("Translation.$locale.$field.id", array(
+ 'value' => $translation['Translation']['id']));
+ echo $this->Form->input("Translation.$locale.$field.content", array(
+ 'type' => 'string',
+ 'label' => sprintf('Field %s, locale %s', $field, $locale),
+ 'value' => $translation['Translation']['content']));
+ }
+
+ ?>
+ </fieldset>
+<?php echo $this->Form->end(__('Submit', true));?>
+</div>
+<div class="actions">
+ <ul>
+ <li><?php echo $this->Html->link(__('List Translations', true), array('action' => 'index'));?></li>
+ </ul>
+</div>
View
80 views/translations/admin_index.ctp
@@ -0,0 +1,80 @@
+<div class="translations index">
+<h2><?php __('Translations');?></h2>
+<p>
+<?php
+echo $this->Paginator->counter(array(
+'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
+));
+?></p>
+<div>
+
+<?php
+ echo $this->Form->create('Translation', array('action' => 'index'));
+
+ echo $this->Form->input("locale", array(
+ 'type' => 'text',
+ 'label' => __('Locale Name', true)));
+ echo $this->Form->input("model", array(
+ 'type' => 'text',
+ 'label' => __('Model Name', true)));
+ echo $this->Form->input("field", array(
+ 'type' => 'text',
+ 'label' => __('Field', true)));
+ echo $this->Form->input("content", array(
+ 'type' => 'text',
+ 'label' => __('Content', true)));
+
+ echo $this->Form->end(__('Search', true));
+
+?>
+</div>
+<table cellpadding="0" cellspacing="0">
+<tr>
+ <th><?php echo $this->Paginator->sort('locale');?></th>
+ <th><?php echo $this->Paginator->sort('model');?></th>
+ <th><?php echo $this->Paginator->sort('foreign_key');?></th>
+ <th><?php echo $this->Paginator->sort('field');?></th>
+ <th><?php echo $this->Paginator->sort('content');?></th>
+ <th class="actions"><?php __('Actions');?></th>
+</tr>
+<?php
+$i = 0;
+foreach ($translations as $translation):
+ $class = null;
+ if ($i++ % 2 == 0) {
+ $class = ' class="altrow"';
+ }
+?>
+ <tr<?php echo $class;?>>
+ <td>
+ <?php echo $translation['Translation']['locale']; ?>
+ </td>
+ <td>
+ <?php echo $translation['Translation']['model']; ?>
+ </td>
+ <td>
+ <?php echo $translation['Translation']['foreign_key']; ?>
+ </td>
+ <td>
+ <?php echo $translation['Translation']['field']; ?>
+ </td>
+ <td>
+ <?php echo $translation['Translation']['content']; ?>
+ </td>
+ <td class="actions">
+ <?php echo $this->Html->link(__('View', true), array('action' => 'view', $translation['Translation']['id'])); ?>
+ <?php echo $this->Html->link(__('Edit', true), array('action' => 'edit', $translation['Translation']['id'])); ?>
+ <?php echo $this->Html->link(__('Edit All locales for this entry', true), array('action' => 'edit_multi', $translation['Translation']['model'], $translation['Translation']['foreign_key'])); ?>
+ <?php echo $this->Html->link(__('Delete', true), array('action' => 'delete', $translation['Translation']['id'])); ?>
+ </td>
+ </tr>
+<?php endforeach; ?>
+</table>
+<?php echo $this->element('paging', array('plugin' => 'templates')); ?>
+</div>
+
+<div class="actions">
+ <ul>
+ <li><?php echo $this->Html->link(__('New Translation', true), array('action' => 'add')); ?></li>
+ </ul>
+</div>
View
43 views/translations/admin_view.ctp
@@ -0,0 +1,43 @@
+<div class="translations view">
+<h2><?php __('Translation');?></h2>
+ <dl><?php $i = 0; $class = ' class="altrow"';?>
+ <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Id'); ?></dt>
+ <dd<?php if ($i++ % 2 == 0) echo $class;?>>
+ <?php echo $translation['Translation']['id']; ?>
+ &nbsp;
+ </dd>
+ <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Locale'); ?></dt>
+ <dd<?php if ($i++ % 2 == 0) echo $class;?>>
+ <?php echo $translation['Translation']['locale']; ?>
+ &nbsp;
+ </dd>
+ <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Model'); ?></dt>
+ <dd<?php if ($i++ % 2 == 0) echo $class;?>>
+ <?php echo $translation['Translation']['model']; ?>
+ &nbsp;
+ </dd>
+ <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Foreign Key'); ?></dt>
+ <dd<?php if ($i++ % 2 == 0) echo $class;?>>
+ <?php echo $translation['Translation']['foreign_key']; ?>
+ &nbsp;
+ </dd>
+ <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Field'); ?></dt>
+ <dd<?php if ($i++ % 2 == 0) echo $class;?>>
+ <?php echo $translation['Translation']['field']; ?>
+ &nbsp;
+ </dd>
+ <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Content'); ?></dt>
+ <dd<?php if ($i++ % 2 == 0) echo $class;?>>
+ <?php echo $translation['Translation']['content']; ?>
+ &nbsp;
+ </dd>
+ </dl>
+</div>
+<div class="actions">
+ <ul>
+ <li><?php echo $this->Html->link(__('Edit Translation', true), array('action' => 'edit', $translation['Translation']['id'])); ?> </li>
+ <li><?php echo $this->Html->link(__('Delete Translation', true), array('action' => 'delete', $translation['Translation']['id'])); ?> </li>
+ <li><?php echo $this->Html->link(__('List Translations', true), array('action' => 'index')); ?> </li>
+ <li><?php echo $this->Html->link(__('New Translation', true), array('action' => 'add')); ?> </li>
+ </ul>
+</div>

0 comments on commit 42d0405

Please sign in to comment.
Something went wrong with that request. Please try again.