Skip to content

Commit

Permalink
Prevent plural translations errors when not logged in; fixes #2949
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Oct 12, 2017
1 parent a3dc186 commit 6093725
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions inc/autoload.function.php
Expand Up @@ -168,6 +168,14 @@ function _e($str, $domain='glpi') {
function _n($sing, $plural, $nb, $domain='glpi') {
global $TRANSLATE;

if (is_null($TRANSLATE)) { // before login
if ($nb == 0 || $nb > 1) {
return $plural;
} else {
return $sing;
}
}

return $TRANSLATE->translatePlural($sing, $plural, $nb, $domain);
}

Expand All @@ -185,8 +193,6 @@ function _n($sing, $plural, $nb, $domain='glpi') {
* @return protected string (with htmlentities)
**/
function _sn($sing, $plural, $nb, $domain='glpi') {
global $TRANSLATE;

return htmlentities(_n($sing, $plural, $nb, $domain), ENT_QUOTES, 'UTF-8');
}

Expand Down Expand Up @@ -344,4 +350,4 @@ function glpi_autoload($classname) {
require_once $autoload;

// Use spl autoload to allow stackable autoload.
spl_autoload_register('glpi_autoload', false, true);
spl_autoload_register('glpi_autoload', false, true);

0 comments on commit 6093725

Please sign in to comment.