Project

General

Profile

Actions

Bug #93346

open

LocalizationUtility::translate throws uncaught exception, if the arguments contains an empty array

Added by Dieter Porth over 3 years ago. Updated about 3 years ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Localization
Target version:
-
Start date:
2021-01-22
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
9
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description


$kye = "hallo %s",  
$param=[];
sprintf($kye, ...array_values($param));


The code above throws an exception. This exception is uncaught in LocalizationUtility::translate.

I use something like this often. A meaningful exception woul be nice.

$argList = [];
$webTitle = LocalizationUtility::translate(
    $item['title'],
    'myExtension',
    $argList
);
                                }

Files

local_history.patch (1.79 KB) local_history.patch Dieter Porth, 2021-01-22 11:11
Actions #1

Updated by Dieter Porth over 3 years ago

  • Subject changed from LocalizationUtility::translate throws uncaught exception to LocalizationUtility::translate throws uncaught exception, if the arguments contains an empty array

A similiar php-code to the presente example above will found in the method (Line 123-129)


        if (is_array($arguments) && $value !== null) {
            // This unrolls arguments from $arguments - instead of calling vsprintf which receives arguments as an array.
            // The reason is that only sprintf() will return an error message if the number of arguments does not match
            // the number of placeholders in the format string. Whereas, vsprintf would silently return nothing.
            return sprintf($value, ...array_values($arguments)) ?: sprintf('Error: could not translate key "%s" with value "%s" and %d argument(s)!', $key, $value, count($arguments));
        }

Actions #2

Updated by Riccardo De Contardi about 3 years ago

  • Category set to Localization
Actions

Also available in: Atom PDF