Provide a PluralTranslatableMarkup::getPluralVariantIndex() factory method

Created on 15 July 2016, almost 9 years ago
Updated 30 January 2023, about 2 years ago

Problem/Motivation

\Drupal\Core\StringTranslation\PluralTranslatableMarkup::getPluralIndex is needed also in other places, see [PP-1] Allow plurals on bundle labels Postponed but right now is a protected method.

Proposed resolution

  1. 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) {
      ...
    }
    
  2. 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.

📌 Task
Status

Needs work

Version

10.1

Component
Language system 

Last updated 7 days ago

  • Maintained by
  • 🇩🇪Germany @sun
Created by

🇷🇴Romania claudiu.cristea Arad 🇷🇴

Live updates comments and jobs are added and updated live.
  • D8MI

    (Drupal 8 Multilingual Initiative) is the tag used by the multilingual initiative to mark core issues (and some contributed module issues). For versions other than Drupal 8, use the i18n (Internationalization) tag on issues which involve or affect multilingual / multinational support. That is preferred over Translation.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The 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.

Production build 0.71.5 2024