Skip to content

Commit

Permalink
Merge branch '21.0' of [email protected]:Dolibarr/dolibarr.git into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jan 28, 2025
2 parents 838ffdc + b9fd853 commit 6b38b32
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
6 changes: 4 additions & 2 deletions htdocs/core/class/translate.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,8 @@ public function trans($key, $param1 = '', $param2 = '', $param3 = '', $param4 =
}
}

$str = preg_replace('/([^%])%([^0sd])/', '__percent_parenthesis__', $str);

$str = preg_replace('/([^%])%([^%0sdmYIMpHSBb])/', '\1__percent_with_bad_specifier__\2', $str);

if (strpos($key, 'Format') !== 0) {
try {
Expand All @@ -693,7 +694,8 @@ public function trans($key, $param1 = '', $param2 = '', $param3 = '', $param4 =
}
}

$str = str_replace('__percent_parenthesis__', '%)', $str);
$str = str_replace('__percent_with_bad_specifier__', '%', $str);


// We replace some HTML tags by __xx__ to avoid having them encoded by htmlentities because
// we want to keep '"' '<b>' '</b>' '<u>' '</u>' '<i>' '</i>' '<center> '</center>' '<strong' '</strong>' '<a ' '</a>' '<br>' '<span' '</span>' '< ' that are reliable HTML tags inside translation strings.
Expand Down
42 changes: 40 additions & 2 deletions test/phpunit/LangTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* \remarks To run this script as CLI: phpunit filename.php
*/

global $conf,$user,$langs,$db;
global $conf, $user, $langs, $db;
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
//require_once 'PHPUnit/Autoload.php';
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
Expand Down Expand Up @@ -104,7 +104,7 @@ public function langDataProvider(): array
}

/**
* testLang
* testTransWithHTMLInParam
*
* @return void
*/
Expand Down Expand Up @@ -138,6 +138,44 @@ public function testTransWithHTMLInParam(): void
return;
}

/**
* testTransWithPercent
*
* @return void
*/
public function testTransWithPercent(): void
{
global $conf,$user,$langs,$db;
$conf = $this->savconf;
$user = $this->savuser;
$langs = $this->savlangs;
$db = $this->savdb;

include_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';

$newlang = new Translate('', $conf);
$newlang->setDefaultLang('fr_FR');
$newlang->load("main");

$result = $newlang->trans("DatabaseConnection");
print "result=".$result.PHP_EOL;
$this->assertEquals('Connexion &agrave; la base', $result);

$result = $newlang->transnoentities("FormatDateHourSecShort");
print "result=".$result.PHP_EOL;
$this->assertEquals('%d/%m/%Y %H:%M:%S', $result);

$newlang = new Translate('', $conf);
$newlang->setDefaultLang('en_US');
$newlang->load("main");

$result = $newlang->transnoentities("FormatDateHourText");
print "result=".$result.PHP_EOL;
$this->assertEquals('%B %d, %Y, %I:%M %p', $result);

return;
}

/**
* testLang
* @dataProvider langDataProvider
Expand Down

0 comments on commit 6b38b32

Please sign in to comment.