Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No deep pluralization fetchChoice hook existing anymore #1659

Open
valoricDe opened this issue Dec 12, 2023 · 0 comments
Open

No deep pluralization fetchChoice hook existing anymore #1659

valoricDe opened this issue Dec 12, 2023 · 0 comments

Comments

@valoricDe
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant