WordPress translate string in array - arrays

I have created a WordPress theme options page in which all options/settings are in an array. Now those strings in the arrays refuse to be translated.
How can I get it so that the strings in my arrays will be translated?
// create theme options
global $cc_options;
$cc_options = array (
// General settings
array( 'name' => __('General', 'cc_language'),
'slug' => 'general',
'status' => 'active',
'type' => 'section'),
array( 'name' => __('Setup some general settings for the website.', 'cc_language'),
'type' => 'section_desc'),
array( 'type' => 'open'),
array( 'name' => __('Breadcrumbs', 'cc_language'),
'type' => 'section_category'),
array( 'name' => __('Enable breadcrumbs', 'cc_language'),
'desc' => __('Check to enable breadcrumbs on pages and posts.', 'cc_language'),
'id' => 'breadcrumbs',
'type' => 'checkbox',
'std' => 'true'),
array( 'type' => 'close'),
);

Your options array needs to be defined after wordpress has initalized its translation routines. Try putting the declaration in an init action hook.

Related

TYPO3 Custom Content fields on save database error

I added some content Fields which looks as it follows;
$temporaryColumnHC = array(
'my_type' => array(
'exclude' => 0,
'label' => 'My Type',
'config' => array(
'type' => 'select',
'renderType' => 'selectSingle',
'items' => array(
array('Bar', 'bar'),
array('Pie', 'pie'),
array('Donut', 'donut'),
array('Line', 'line'),
array('Bar 2', 'bar2'),
array('Bar 3', 'bar3'),
array('Bubble', 'bubble'),
)
)
),
'my_suffix' => array(
'exclude' => 0,
'label' => 'My Label Suffix',
'config' => array(
'type' => 'input',
'size' => 10,
'max' => 20
)
),
'my_source_url' => array(
'exclude' => 0,
'label' => 'Source URL',
'config' => array(
'type' => 'input',
'renderType' => 'inputLink'
)
),
'my_source' => array(
'exclude' => 0,
'label' => 'Source Text',
'config' => array(
'type' => 'text',
'cols' => 40,
'rows' => 15
)
),
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tt_content',
$temporaryColumnHC
);
but on save I get the following error
error [1620]: Unknown column 'suffix' in 'field list'
What I have to do that this fields is saved in database
As mentioned already as a comment, TYPO3 complains that the column is missing in the Database.
Your extension should provide an ext_tables.sql which extends the Database Schema. See https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ExtensionArchitecture/FilesAndLocations/Index.html#ext-tables-sql for further information.
The file always contains CREATE TABLE statements, which will be converted by TYPO3 do update the schema.
Updating the schema can be done through the install tool of TYPO3, or tools like TYPO3 console via command line.

setting default 'SELECTED' in checkbox elements of zend 2 forms

I want to set a default 'selected' for my checkbox in zend 2.
i tried adding a default
'value'=>'selected'
but it does not seem to work.
$this->add(array(
'type' => 'Zend\Form\Element\Checkbox',
'name' => 'receiveNewsletters',
'options' => array(
'value_options' => array(
'1' => 'Untick if you do not want to receive promotional emails',
),
'attributes' => array(
'value'=>'selected',
),
),
));
The value should be the checked_value. By default it is '1'
$this->add(array(
'type' => 'Zend\Form\Element\Checkbox',
'name' => 'receiveNewsletters',
'options' => array(
'label' => 'Untick if you do not want to receive promotional emails',
),
'attributes' => array(
'value' => '1',
),
));

cakephp find(all) optimization

I am using cakephp 2.5.2
I have 5 tables
1- users
2- projects
3- tags
4- project_tags
5- images
a user can have many projects
a project can have many (tags,images)
I have 2 questions
$projects = $this->Project->find('all',array('conditions'=>array('User.id'=>$this->Auth->user('id'))));
debug($projects);exit();
this gives
array(
(int) 0 => array(
'Project' => array(
'id' => '1',
'name' => 'project 1'
),
'User' => array(
'password' => '*****',
'id' => '1',
'name' => 'User 1',
'email' => 'user1#gmail.com'
),
'Image' => array(),
'ProjectTag' => array(
(int) 0 => array(
'id' => '1',
'project_id' => '1',
'tag_id' => '1'
),
(int) 1 => array(
'id' => '2',
'project_id' => '1',
'tag_id' => '8'
),
(int) 2 => array(
'id' => '3',
'project_id' => '1',
'tag_id' => '6'
),
(int) 3 => array(
'id' => '4',
'project_id' => '1',
'tag_id' => '10'
),
(int) 4 => array(
'id' => '5',
'project_id' => '1',
'tag_id' => '4'
)
)
),
(int) 1 => array(
'Project' => array(
'id' => '2',
'name' => 'project 2'
),
'User' => array(
'password' => '*****',
'id' => '1',
'name' => 'user 1',
'email' => 'user1#gmail.com'
),
'Image' => array(),
'ProjectTag' => array(
(int) 0 => array(
'id' => '6',
'project_id' => '2',
'tag_id' => '1'
),
(int) 1 => array(
'id' => '7',
'project_id' => '2',
'tag_id' => '8'
),
(int) 2 => array(
'id' => '8',
'project_id' => '2',
'tag_id' => '4'
)
)
)
)
I need Project & ProjectTag array while do not want user and images array
I tried recursive -1,0,1,2 but could not get what I needed
My Question Number 2 is
How can I find projects which has tag = 'html'
$projects = $this->Project->find('all',array('conditions'=>array('Tag.tag'=>'HTML')));
it says
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Tag.tag' in 'where clause'
First off, just a note. ALWAYS use $recursive=-1;. It's ideal just to set this in the AppModel, then never mess with recursive again. If you want to get additional data, use CakePHP's Containable Behavior, not recursive.
Overall issue - you cannot add conditions against a recursive (or contained) model, which is what you appear to be doing in both of your questions. If you want to condition against a model other than the one you're doing the find on, you need to either use JOINs or swap your query to run on the other model.
Answer to Question 1
Change this:
$projects = $this->Project->find('all',array(
'conditions'=>array(
'User.id'=>$this->Auth->user('id')
)
));
To this:
$projects = $this->Project->find('all',array(
'conditions'=>array(
'user_id'=>$this->Auth->user('id') // <-- notice this
),
'contain' => array(
'ProjectTag' => array(
'Tag' // <-- optional, as you didn't mention you needed
)
)
));
Answer to Question 2:
There are a number of ways to do this. I would suggest this one using joins:
$projects = $this->Project->find('all', array(
'fields' => array(
'Project.*',
'Tag.*'
),
'joins'=>array(
array(
'table' => 'tags',
'alias' => 'Tag',
'type' => 'inner',
'conditions' => array(
'Tag.project_id = Project.id',
'Tag.tag' => 'HTML'
)
)
)
));
Another way would be to swap your query to run on Tags and just use contain to contain the projects for that tag. I like the join better because if you ever way to extend it to retrieve projects for more than just one tag, your data will still be in an easy-to use manner, as opposed to Containable, which would put your projects in different arrays under their corresponding tag.
If you want to optimize your queries in CakePHP, turn off recursive (set it to -1), then use the containable behavior to pick and choose exactly which data you need.
As for your specific query, associated models are by default gotten by left joins, which means if you did your query from projects, you will get all projects plus any tags they have that have "html" in their tag field. The easiest way to fix this problem, is to do your search from tags instead:
$tags = $this->Tag->find('first', array('conditions' => array('tag' => 'html'), 'contain' => array('Project')));
This will get the tag that has 'html' for its tag field, and all the projects associated with it.

Containable to do show deeper data or join table

I have 3 tables: projects, project_reminder_users, project_types.
The relations is as follow:
Project => belong to => ProjectType
hasMany => ProjectReminderUser
ProjectReminderUser => belong to => Project
ProjectType => hasMany => Project
I get all data based on who assigned(ProjectReminderUser) by this
$this->Project->ProjectReminderUser->Behaviors->load('Containable');
$this->paginate = array(
'ProjectReminderUser' => array(
'limit' => $limit,
'contain' => array(
'Project' => array(
'ProjectComment',
'ProjectFile',
),
'User'
),
'conditions' => array(
'User.group_id' => $this->Session->read('Auth.User.group_id'),
'ProjectReminderUser.user_id' => $this->Session->read('Auth.User.id'),
'Project.project_status_id' => PROJECT_STATUS_OPEN,
),
'order' => 'Project.due_date',
)
);
$this->set('myTasks', $this->paginate('ProjectReminderUser'));
and the result look like this
array(
'ProjectReminderUser' => array(
'id' => '96',
'user_id' => '1',
'project_id' => '46'
),
'Project' => array(
'id' => '46',
'project_type_id' => '9',
'contact_id' => null,
'company_id' => null,
'subject' => 'Test Modified Field',
'description' => 'Test Modified Field',
'ProjectFile' => array(
(int) 0 => array(
'id' => '19',
'project_id' => '46',
'user_id' => '6',
'file_path' => '46_bhbinary_xmm_1728.jpg',
'notes' => null,
'created' => '2013-11-26 18:37:49'
),
),
'ProjectComment' => array(
)
),
'User' => array(
'password' => '*****',
'id' => '1',
'group_id' => '1',
'email' => 'xxx#xxxxx.com',
'first_name' => 'xxxx',
'deleted' => false,
'displayName' => 'xxxxx'
)
)
In the result There is data for Project.project_type_id, but I would like to have more detail of that. So I can show it as name instead of number. maybe like ProjectType.name instead.
How can I achieve this, so I can sort it in the view? something like this
$this->Paginator->sort('ProjectType.name', 'Type');
The problem is that Paginator doesn't play nice with deep model associations. I think though if rather than using Cake's methods for doing model associations, you instead do your joins manually, you may be able to work out the sorting as you want. See the below discussion.
http://sinkpoint.railsplayground.net/cakephp-pagination-deep-sort-and-habtm/
Worst comes to worse, you may have to also rewrite the model's paginate function to deal with sorting how you need it to.
How about
'contain' => array(
'Project' => array(
'ProjectComment',
'ProjectFile',
'ProjectType',
),
'User'
),
Looks like you did not contain "ProjectType"

yii booster checkbox doesn't show boxes to check

I add the checkbox functionality from the yii-booster. But the widget renders the model view without the needed boxes. What's wrong?
Widjet code in view
<?php
$this->widget('bootstrap.widgets.TbExtendedGridView',array(
'id'=>'docs-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'type'=>'bordered condensed',
'template' => "{items}",
'bulkActions' => array(
'actionButtons' => array(
array(
'buttonType' => 'button',
'type' => 'primary',
'size' => 'small',
'label' => 'Choose',
'click' => 'js:function(values){console.log(values);}'
)
),
// if grid doesn't have a checkbox column type, it will attach
// one and this configuration will be part of it
'checkBoxColumnConfig' => array(
'name' => 'id'
),
),
));
If you are using bulkActions, you have to use 'columns' to list out the columns you want to display instead of using 'template'.
'columns' => array(
'id',
'title',
...
),
the problem has been in the wrong hierarchy from the example:
The 'checkBoxColumnConfig' attribute must be outside of the 'actionButtons' attribute:
'bulkActions' => array(
'actionButtons' => array(
/*array(
'buttonType' => 'button',
'type' => 'primary',
'size' => 'small',
'label' => 'Выбрать отмеченные',
'click' => 'js:function(values){console.log(values);}'
)
),*/
// if grid doesn't have a checkbox column type, it will attach
// one and this configuration will be part of it
),
'checkBoxColumnConfig' => array(
'name' => 'id'
),
...
));
but now the widget doesn't work when i uncomment the array part inside 'actionButtons':
array(
'buttonType' => 'button',
'type' => 'primary',
'size' => 'small',
'label' => 'Выбрать отмеченные',
'click' => 'js:function(values){console.log(values);}'
)
what might be a cause?

Resources