Roundcube Community Forum

Third Party Contributions => API Based Plugins => Topic started by: marco-shagrat on May 22, 2015, 04:36:17 AM

Title: Extra fields in "edit identity" form
Post by: marco-shagrat on May 22, 2015, 04:36:17 AM
Hi all,
  i need to add a custom field to the identity form.

I did a plugin that interacts with "identity_form" hook. All is working well (the extra field is correctly displayed) but i have problems with localization.

My plugin adds a my custom field to the "original form" array:

Array
(
    [form] => Array
        (
            [addressing] => Array
                (
                    [name] => Impostazioni
                    [content] => Array
                        (
                            [name] => Array
                                (
                                    [type] => text
                                    [size] => 40
                                )
            .....
            [extra_fields] => Array
                (
                    [name] => Extra fields
                    [content] => Array
                        (
                            [my_extra_field] => Array
                                (
                                    [type] => text
                                    [size] => 40
                                )
.....
)


in the localization folder i added my localization file that contains


  ...
  $labels['my_extra_field'] = 'My extra field';
  ...


but in the form the field label is displayed like [my_extra_field]

If i add the $labels['my_extra_field'] = 'My extra field'; row in the general localization file (under program/localization/...) the field label is translated.

How can i solve this problem?

Any help is really appreciated!

Title: Re: Extra fields in "edit identity" form
Post by: SKaero on May 23, 2015, 12:54:09 PM
Are you loading the new localization file?
Title: Re: Extra fields in "edit identity" form
Post by: marco-shagrat on May 23, 2015, 03:06:25 PM
Yes,
  in the init method.


$this->add_texts('localization/', true);


Title: Re: Extra fields in "edit identity" form
Post by: SKaero on May 24, 2015, 01:23:19 AM
What is the file name that the you've put the localization in? How are you using the localized text?
Title: Re: Extra fields in "edit identity" form
Post by: marco-shagrat on May 24, 2015, 10:23:03 AM
Here the partial code of my plugin (it may help):


function init()
{
$this->add_texts('localization/', true); //in this directory there are two files called it_IT.ing and en_US.inc (this is mandatory reading the documentation)

$this->load_config('config.inc.php');

$this->add_hook('identity_form', array($this, 'add_identity_extra_fields'));
}

function add_identity_extra_fields($data)
{
$rcmail = rcmail::get_instance();

$db = $rcmail->db;

$query_params = array($data['record']['user_id']);

$query = '';

$query .= 'SELECT my_extra_field FROM .... ';

$result = $db->query($query, $query_params)->fetchAll();

$my_extra_field_value = count($result) ? $result[0]['my_extra_field'] : '';

$data['form']['extra_fields']['name'] = $this->gettext('extra_fields'); // this label is correctly translated

$data['form']['extra_fields']['content'] =
array('my_extra_field' => array('type' => 'text', 'size' => 40));

$data['record']['my_extra_field'] = $my_extra_field_value;  //the "my_extra_field" label is not translated but the translation exists in it_IT.inc and en_US.inc

return $data;
}



if I put the translation in "program/localization/it_IT/labels.inc" the label is correctly displayed.
Title: Re: Extra fields in "edit identity" form
Post by: JohnDoh on May 25, 2015, 03:16:22 AM
You should put the localization file for you plugin in you plugin folder not append it to the core files. See http://trac.roundcube.net/wiki/Doc_Plugins#Internationalization
Title: Re: Extra fields in "edit identity" form
Post by: marco-shagrat on May 26, 2015, 12:50:22 PM
My localization file IS in the localization folder of the plugin but does not work for that specific label
In my previous post there is a description where local plugin localization works and where it does not work.
Title: Re: Extra fields in "edit identity" form
Post by: alec on May 27, 2015, 02:34:12 AM
Try 'plugin_name.my_extra_field' instead.
Title: Re: Extra fields in "edit identity" form
Post by: marco-shagrat on May 27, 2015, 11:20:31 AM
I already tried this solution. Unfortunately it does not work.

The field name ('<input name="..") changes (this is not a problem) but the label is still displayed in square brackets not translated.