pluginsGLPI / formcreator

GLPI Plugin Formcreator (DOWNLOAD : https://github.com/pluginsGLPI/formcreator/releases)
http://www.teclib-edition.com
GNU General Public License v3.0
174 stars 125 forks source link

feat(DropdownField): Load translation for plugin too #3377

Closed stonebuzz closed 1 year ago

stonebuzz commented 1 year ago

Changes description

To follow https://github.com/pluginsGLPI/formcreator/pull/3367

$_SESSION['glpilanguage'] need to be set too.

Some plugin can check this key to load desired langage.

See genericobject for example

function plugin_genericobject_includeCommonFields($force = false) {
   global $GO_FIELDS, $LANG; // Permit missing global declaration in user files

   $includes = [
       sprintf('%s/fields/field.constant.php', GENERICOBJECT_DIR), // Default common fields constants
   ];

   // User locales for common fields
   if (
      isset($_SESSION['glpilanguage'])
      && file_exists($locale_file = sprintf('%s/fields.%s.php', GENERICOBJECT_LOCALES_PATH, $_SESSION['glpilanguage']))
   ) {
      $includes[] = $locale_file;
   } elseif (file_exists($locale_file = sprintf('%s/fields.%s.php', GENERICOBJECT_LOCALES_PATH, 'en_GB'))) {
      $includes[] = $locale_file;
   }

   // User common fields constants
   if (file_exists($fields_file = sprintf('%s/field.constant.php', GENERICOBJECT_FIELDS_PATH))) {
      $includes[] = $fields_file;
   }

   foreach ($includes as $include) {
      if (!$force) {
         include_once($include);
      } else {
         include($include);
      }
   }
}

Checklist

Please check if your PR fulfills the following specifications:

References

Internal ref 29394

Closes #N/A