Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged

Conversation

stonebuzz
Copy link
Contributor

@stonebuzz stonebuzz commented Sep 28, 2023

Changes description

To follow #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:

  • Tests for the changes have been added
  • Docs have been added/updated

References

Internal ref 29394

Closes #N/A

@stonebuzz stonebuzz requested a review from btry September 28, 2023 12:32
@stonebuzz stonebuzz self-assigned this Sep 28, 2023
@stonebuzz stonebuzz added the bug label Sep 28, 2023
@stonebuzz stonebuzz added this to the 2.13.8 milestone Sep 28, 2023
@stonebuzz stonebuzz marked this pull request as draft September 28, 2023 12:33
@stonebuzz stonebuzz marked this pull request as ready for review September 28, 2023 12:44
@@ -715,6 +715,7 @@ public function parseObjectProperties(
// We need english locale to search searchOptions by name
$oldLocale = $TRANSLATE->getLocale();
$TRANSLATE->setLocale("en_GB");
$_SESSION['glpilanguage'] = "en_GB";
Copy link
Collaborator

@btry btry Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could maybe replace $TRANSLATE->setLocale("en_GB"); and $_SESSION['glpilanguage'] = "en_GB"; with a single call to Session::loadLanguage().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I'm not mistaken Session::loadLanguage(). does not overload $_SESSION['glpilanguage'] with $forcelang

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Then I approve this solution.

@btry btry merged commit 16a1379 into pluginsGLPI:support/2.13.0 Sep 29, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants