Roundcube Community Forum

 

Extra fields in "edit identity" form

Started by marco-shagrat, May 22, 2015, 04:36:17 AM

Previous topic - Next topic

marco-shagrat

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!


SKaero

Are you loading the new localization file?

marco-shagrat

Yes,
  in the init method.


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



SKaero

What is the file name that the you've put the localization in? How are you using the localized text?

marco-shagrat

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.

JohnDoh

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
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more...

marco-shagrat

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.

alec

Try 'plugin_name.my_extra_field' instead.

marco-shagrat

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.