You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2022-06-28 12:16:04

wolvverinemp
Member
From: Poland
Registered: 2021-09-20
Posts: 31

[RESOLVED] How add locales for new defined global fields-GenericObject

How add locales for new global fields defined in
<GLPI_ROOT>/files/_plugins/genericobject/fields/field.constant.php

example:

<?php
global $GO_FIELDS, $LANG;

$GO_FIELDS['plugin_genericobject_orgunits_id']['name']       = $LANG['genericobject']['globalfields'][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']['globalfields'][2];
$GO_FIELDS['idfield']['input_type'] = 'text';

?>

documentation do not say this:
https : //glpi-plugins.readthedocs.io/ro/latest/genericobject/index.html#add-global-fields
Only for fields specific for new assets are in manual.

Translation file:

<?php
// Fields
$LANG['genericobject']['globalfields'][1]="Organizational Unit"; 
$LANG['genericobject']['globalfields'][2]="ID";

Where and under what names should I place the translation files for global fields ...

When placing in a directory:
<GLPI_ROOT>/files/_plugins/genericobject/locales/
file:
field.en_US.php

the fields are not displayed.

Last edited by wolvverinemp (2022-10-04 11:53:41)

Offline

#2 2022-06-29 13:41:14

wolvverinemp
Member
From: Poland
Registered: 2021-09-20
Posts: 31

Re: [RESOLVED] How add locales for new defined global fields-GenericObject

I added function plugin_genericobject_includeCommonFieldsLocale in setup.php:

function plugin_genericobject_includeCommonFields($force = false) {
   //Load genericobject default constants
   if (!$force) {
      include_once (GENERICOBJECT_DIR."/fields/field.constant.php");
   } else {
      include (GENERICOBJECT_DIR."/fields/field.constant.php");
   }

   //Include user constants, that must be accessible for all itemtypes
   if (file_exists(GENERICOBJECT_FIELDS_PATH . "/field.constant.php")) {
      if (!$force) {
         include_once ( GENERICOBJECT_FIELDS_PATH . "/field.constant.php");
      } else {
         include ( GENERICOBJECT_FIELDS_PATH . "/field.constant.php");
      }
      plugin_genericobject_includeCommonFieldsLocale($force);
   }
}

function plugin_genericobject_includeCommonFieldsLocale($force = false) {
   //Include user constants locales accessible for all itemtypes
   if (isset ($_SESSION["glpilanguage"])) {
      $locale_common_file ='field' . '.' . $_SESSION['glpilanguage'];
      if (file_exists( GENERICOBJECT_LOCALES_PATH . '/' . "$locale_common_file.php")) {
         if(!$force) {
            include_once ( GENERICOBJECT_LOCALES_PATH . '/' . "$locale_common_file.php");
         }
         else {
            include ( GENERICOBJECT_LOCALES_PATH . '/' . "$locale_common_file.php");
         }
      }
   } else {
      if (file_exists( GENERICOBJECT_LOCALES_PATH . '/field.en_GB.php')) {
         if(!$force) {
            include_once ( GENERICOBJECT_LOCALES_PATH . '/field.en_GB.php');
         }
         else {
            include ( GENERICOBJECT_LOCALES_PATH . '/field.en_GB.php');
         }
      } else {
         return false;
      }
   }
}

Unfortunately, it does not load language files, is there anywhere else I need to add/change something?

Last edited by wolvverinemp (2022-06-29 13:41:54)

Offline

#3 2022-07-01 00:28:21

wolvverinemp
Member
From: Poland
Registered: 2021-09-20
Posts: 31

Re: [RESOLVED] How add locales for new defined global fields-GenericObject

Problem solved.

function plugin_genericobject_includeCommonFields($force = false) {
   
   //Load genericobject default constants
   if (!$force) {
      include_once (GENERICOBJECT_DIR."/fields/field.constant.php");
   } else {
      include (GENERICOBJECT_DIR."/fields/field.constant.php");
   }

   //Include user constants, that must be accessible for all itemtypes
   if (file_exists(GENERICOBJECT_FIELDS_PATH . "/field.constant.php")) {
      // Load locales
      plugin_genericobject_includeCommonFieldsLocale($force);
      if (!$force) {
         include_once ( GENERICOBJECT_FIELDS_PATH . "/field.constant.php");
      } else {
         include ( GENERICOBJECT_FIELDS_PATH . "/field.constant.php");
      }
   }
}


function plugin_genericobject_includeCommonFieldsLocale($force = false) {
   global $CFG_GLPI,$LANG;
   //Include user constants locales accessible for all itemtypes

   if (isset ($_SESSION["glpilanguage"])) {
      $locale_common_file ='field' . '.' . $_SESSION['glpilanguage'];
      if (file_exists( GENERICOBJECT_LOCALES_PATH . "/$locale_common_file.php")) {
         if(!$force) {
            include_once ( GENERICOBJECT_LOCALES_PATH . "/$locale_common_file.php");
         }
         else {
            include ( GENERICOBJECT_LOCALES_PATH . "/$locale_common_file.php");
         }         
      }
   } else {
      if (file_exists( GENERICOBJECT_LOCALES_PATH . "/field.en_GB.php")) {
         if(!$force) {
            include_once ( GENERICOBJECT_LOCALES_PATH . "/field.en_GB.php");
         }
         else {
            include ( GENERICOBJECT_LOCALES_PATH . "/field.en_GB.php");
         }
      } else {
         return false;
      }
   }
}

Pull request.

https hmm/github.com/pluginsGLPI/genericobject/pull/338

Last edited by wolvverinemp (2022-07-01 03:16:09)

Offline

#4 2022-10-04 11:59:50

wolvverinemp
Member
From: Poland
Registered: 2021-09-20
Posts: 31

Re: [RESOLVED] How add locales for new defined global fields-GenericObject

The fix has been implemented in the latest version of the plugin.

The translations are placed in the directory:

[GLPI_ROOT]/_plugins/genericobject/locales/.

in the files:

fields.en_GB.php
fields.en_US.php
fields.pl_PL.php
...

Last edited by wolvverinemp (2024-06-04 17:49:26)

Offline

Board footer

Powered by FluxBB