intlify / vue-i18n

Vue I18n for Vue 3

Home Page:https://vue-i18n.intlify.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No deep pluralization fetchChoice hook existing anymore

valoricDe opened this issue · comments

Previously in version 8 I was able to overwrite the prototype function fetchChoice

VueI18n.prototype.fetchChoice = function fetchChoice(message, choice) { handle things }

message in my case is an object and not a string. That's why the current public function to change the choice making is not enough for me.

But with version 9 and createI18n function I do not know how to do it.
I saw the referenced line (https://github.com/intlify/vue-i18n-next/blob/b5c73ef661e88719cb5d6c40a58e264923230077/packages/core-base/src/runtime.ts#L409C5-L409C36): [HelperNameMap.PLURAL]: plural in createMessageContext.
And I wondered how I can overwrite the Helper plural.

As reference my fetchChoice looks like:

  VueI18n.prototype.fetchChoice = function fetchChoice(message, choice) {
    /* istanbul ignore if */
    if (
      !message &&
      (!isString(message) || (!message.zero && !message.one && !message.other))
    ) {
      return null;
    }
    if (isString(message)) {
      var choices = message.split('|');

      choice = this.getChoiceIndex(choice, choices.length);
      if (!choices[choice]) {
        return message;
      }
      return choices[choice].trim();
    }
    if (message.one || message.other) {
      if (choice === -1 || choice === 1) return message.one || message.other;
      if (choice === 0) return message.zero || message.other;
      return message.other;
    }
  };

Originally posted by @valoricDe in #1657