Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Wrong variable type declaration of DrupalDateTime class's $formatTranslationCache property.
/**
* Format string translation cache.
*
* @var string
*/
protected $formatTranslationCache;
Following is the relevant code snippet from the same class's format() method:
// Translates a formatted date string.
$translation_callback = function ($matches) use ($langcode) {
$code = $matches[1];
$string = $matches[2];
if (!isset($this->formatTranslationCache[$langcode][$code][$string])) {
$options = ['langcode' => $langcode];
if ($code == 'F') {
$options['context'] = 'Long month name';
}
if ($code == '') {
$this->formatTranslationCache[$langcode][$code][$string] = $string;
}
else {
$this->formatTranslationCache[$langcode][$code][$string] = $this->t($string, [], $options);
}
}
return $this->formatTranslationCache[$langcode][$code][$string];
};
Comment | File | Size | Author |
---|---|---|---|
#16 | 3104071-16.patch | 1.36 KB | jungle |
Comments
Comment #2
jungleComment #3
jungleComment #4
jungle(stolen from JohnAlbin's user page as well.)
Am I the winner of Trivial Patch of the Month?
Comment #5
jungleComment #6
andypostWould be great to extend description with details of array
Comment #7
jungleThanks, @andypost for commenting. It's hard for me to add a description :( I tried to understand the code, but could not. Let's wait for the one who would like helping to add more details.
Comment #8
knyshuk.vova CreditAttribution: knyshuk.vova at Internetdevels commented@andypost, thank you for the direction of improvement. I have added more informative description for
$formatTranslationCache
and improved some text to make it more readable.Comment #9
jungleThanks, @knyshuk.vova!
According to https://www.php.net/manual/en/function.sprintf.php, should 'F' be 's'?
Comment #10
knyshuk.vova CreditAttribution: knyshuk.vova at Internetdevels commented@jungle, No, because 'F' and 'd' in my code example is compatible with format character from https://www.php.net/manual/en/function.date.php
Comment #11
jungleCool, you are right!
Comment #12
jungleComment #13
jungleComment #14
alexpottWe're doing more doc fixes here that what the title claims.
Comment #15
alexpottActually putting my scope hat on can we limit the fixes to the original scope
Ie. this bit. The other changes clash with other issues trying to make similar changes on a global code base level. Allowing such changes here weakens the message that such changes should be fixed in the entire codebase first.
Comment #16
jungleOnly borrowed the comment for formatTranslationCache from #8, dropped other changes.
Comment #17
knyshuk.vova CreditAttribution: knyshuk.vova at Internetdevels commentedI think now it is correct.
Comment #18
alexpottCommitted and pushed ceaf783d0b to 9.0.x and d7b34a94d7 to 8.9.x and 456d570452 to 8.8.x. Thanks!
Backported to 8.8.x as a docs fix.