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

Support flexible pluralization #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Support flexible pluralization #2

wants to merge 1 commit into from

Conversation

ajoslin
Copy link
Owner

@ajoslin ajoslin commented Apr 5, 2017

Ref #1. @gertsonderby informed me of how complicated pluralization really is: any range needs to be able to have its own translation.

That's now supported. We're still below 800b payload.

Ranges (inclusive), negative wildcards, and positive wildcards are now supported. A plural value is now just an object with allowed number keys, wildcard keys, and range keys. This means that the array syntax still works.

    PLURALIZED_COMPLEX: {
      '-*': 'Negative fallback with {{count}}.',
      '-3:-6': 'Range -3:-6',
      0: 'Here are {{ count }}',
      1: 'Here is {{ count }}',
      '5:10': 'Five to 10 {{count}}',
      '*': 'And larger: {{ count }}'
    },

This complex value is lazily generated into a function at runtime, only the first time the translation key is requested. It simply becomes something like this:

function anonymous(o,n
/**/) {
if (o[n]) return o[n]
if (n >= -6 && n <= -3) return o["-3:-6"]
if (n >= 5 && n <= 10) return o["5:10"]
return n < 0 ? o["-*"] : o["*"]
}

The wildcards '*' and '-*' default to the largest and smallest values given.

@ajoslin ajoslin changed the title Support extremely flexible pluralization Support flexible pluralization Apr 5, 2017
@ajoslin ajoslin force-pushed the better-plural branch 3 times, most recently from 43ca0b4 to 6f65c87 Compare April 5, 2017 16:43
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

Successfully merging this pull request may close these issues.

1 participant