vue-i18n icon indicating copy to clipboard operation
vue-i18n copied to clipboard

No deep pluralization fetchChoice hook existing anymore

Open valoricDe opened this issue 1 year ago • 0 comments
trafficstars

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 https://github.com/intlify/vue-i18n-next/discussions/1657

valoricDe avatar Dec 12 '23 16:12 valoricDe