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
\Drupal\Core\StringTranslation\PluralTranslatableMarkup::getPluralIndex
is needed also in other places, see #2765065: [PP-1] Allow plurals on bundle labels but right now is a protected method.
Proposed resolution
- Add a new public static factory method to be reused where needed.
/** * Gets the plural index through the gettext formula. * * @param int $count * The count value for witch to retrieve the plural variant index. * @param string $langcode * (optional) The code of the language to be checked. Defaults to current * language. * * @return int * The numeric index of the plural variant to use for this $langcode and * $count combination or -1 if the language was not found or does not have a * plural formula. */ public static function getPluralVariantIndex($count, $langcode = NULL) { ... }
- Deprecate
\Drupal\Core\StringTranslation\PluralTranslatableMarkup::getPluralIndex()
transform it into a simple wrapper around::getPluralVariantIndex
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#22 | 2766857-nr-bot.txt | 1.81 KB | needs-review-queue-bot |
#8 | interdiff-3-to-8.txt | 1011 bytes | claudiu.cristea |
#8 | 2766857-8.patch | 2.38 KB | claudiu.cristea |
Comments
Comment #2
claudiu.cristeaComment #3
claudiu.cristeaComment #4
claudiu.cristeaComment #5
claudiu.cristeaComment #6
claudiu.cristeaComment #8
claudiu.cristeaComment #17
andypostI find it bad idea to keep
function_exists('locale_get_plural')
in core namespaceLet's go with decorator #2660338: locale_get_plural call in PluralTranslatableString is wrong
Comment #22
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.