pluginsGLPI / genericobject

Genericobject object plugin
http://glpi-plugins.rtfd.io/en/latest/genericobject/index.html
GNU General Public License v3.0
53 stars 58 forks source link

Add include locale files for common fields #338

Closed Wolvverine closed 2 years ago

Wolvverine commented 2 years ago

from GENERICOBJECT_LOCALES_PATH/field.[language].php

Wolvverine commented 2 years ago

Please to release for both GLPI 10.x.x and for 9.5.x

Wolvverine commented 2 years ago

@stonebuzz Yes , but only fields for specific itemtype. Not for common fields defined in GENERICOBJECT_FIELDS_PATH/field.constant.php

https://forum.glpi-project.org/viewtopic.php?id=284179

Wolvverine commented 2 years ago

@stonebuzz @cedric-anne

Do you need any more data?

On another note, there is no option for generic plugin to report errors, and there are quite a few in the plugin.

stonebuzz commented 2 years ago

Hello @Wolvverine

Are you trying to load the locales for each field defined in field.constant.php? image

Best regards

stonebuzz commented 2 years ago

You do not need to include these locales, they are provided as standard by GLPI.

This will not work https://github.com/pluginsGLPI/genericobject/blob/a5e5443f25c30ce631b58146969a66f71d2590b0/setup.php#L261-L289

Because for native fields defined in field.constant.php, genericobject use GLPI native locales ex: __("Name"). Also field.constant.php do not have a locale files as field.en_GB.php

Do you want to include locale for any fields that you have added to this file ?

Best regards

Wolvverine commented 2 years ago

Not fields defined in the plugin code, but new global fields created for all new assets. declared in : files/_plugins/genericobject/fields//field.constant.php

image

The plugin writers forgot about the possibility to include extracted translations for these global fields. They only added for fields defined per new asset.

stonebuzz commented 2 years ago

Not fields defined in the plugin code, but new global fields created for all new assets. declared in : files/_plugins/genericobject/fields//field.constant.php

Ok, i see.

Let me check

cedric-anne commented 2 years ago

@Wolvverine

I do not know well how to customize this plugin. Can you attach here custom files required to test this feature ?

Wolvverine commented 2 years ago

Standard way for generic object, example: image

files/_plugins/genericobject/fields//field.constant.php - file with common fields:

<?php
global $GO_FIELDS, $LANG;

$GO_FIELDS['plugin_genericobject_orgunits_id']['name']       = $LANG['genericobject']['commonfields'][1];
$GO_FIELDS['plugin_genericobject_orgunits_id']['field']      = 'Organizational Unit';
$GO_FIELDS['plugin_genericobject_orgunits_id']['input_type'] = 'dropdown';

$GO_FIELDS['idfield']['name'] =  $LANG['genericobject']['commonfields'][2];
$GO_FIELDS['idfield']['input_type'] = 'text';

$GO_FIELDS['data_courier_issuance']['name']        =   $LANG['genericobject']['commonfields'][3];
//   'Date issuance';
$GO_FIELDS['data_courier_issuance']['input_type']  =   'datetime';

$GO_FIELDS['data_courier_return']['name']        =  $LANG['genericobject']['commonfields'][4];
//   'Date return';
$GO_FIELDS['data_courier_return']['input_type']  =   'datetime';

$GO_FIELDS['lease_start_date']['name']        =  $LANG['genericobject']['commonfields'][5];
//   'Lease start date';
$GO_FIELDS['lease_start_date']['input_type']  =   'datetime';

$GO_FIELDS['lease_end_date']['name']        =  $LANG['genericobject']['commonfields'][6];
//   'Lease end date';
$GO_FIELDS['lease_end_date']['input_type']  =   'datetime';

?>

in locales files: files/_plugins/genericobject/locales/field.en_GB.php files/_plugins/genericobject/locales/field.en_US.php files/_plugins/genericobject/locales/field.pl_PL.php files/_plugins/genericobject/locales/field.fr_FR.php etc.

<?php
// Fields
$LANG['genericobject']['commonfields'][1]="Organizational Unit"; 
$LANG['genericobject']['commonfields'][2]="ID";
$LANG['genericobject']['commonfields'][3]="Date issuance"; 
$LANG['genericobject']['commonfields'][4]="Date return";
$LANG['genericobject']['commonfields'][5]="Lease start date"; 
$LANG['genericobject']['commonfields'][6]="Lease end date";
cedric-anne commented 2 years ago

Refactored and cherry-picked in 170a3e5725a4bfae8298720622bec39156ff376b.

I changed filename from field.$lang.php to fields.$lang.php.

cedric-anne commented 2 years ago

Documentation update: https://github.com/pluginsGLPI/doc/pull/61