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

Enhance Pluralization Support: Add PluralForms and Rule Implementations #7

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

teogor
Copy link
Owner

@teogor teogor commented Aug 28, 2024

Enhancement: Pluralization Rules and Utility Functions

This pull request introduces new pluralization functionality to the xenoglot-pluralization module. It adds comprehensive support for handling pluralization rules based on quantity and provides utility functions for formatting strings dynamically.

Key Additions:

  1. PluralForms Class

    • Implements PluralForms to manage a collection of pluralization rules.
    • Includes methods for retrieving formatted strings based on quantity:
      • getQuantityString(quantity: Int): Retrieves the formatted string for the given quantity, throwing an exception if no rule matches.
      • getQuantityStringOrNull(quantity: Int): Retrieves the formatted string or returns null if no rule matches.
      • getQuantityStringOrElse(quantity: Int, fallback: String): Retrieves the formatted string or returns a fallback value if no rule matches.
      • getQuantityStringOrThrow(quantity: Int): Retrieves the formatted string or throws an exception if no rule matches.
  2. PluralizationRule Interface and Implementations

    • Defines the PluralizationRule interface with methods for determining rule matches and providing template strings.
    • Provides implementations for common pluralization rules:
      • ZeroRule, OneRule, TwoRule, FewRule, ManyRule, OtherRule
  3. Utility Functions

    • createPluralForms(): Creates an instance of PluralForms using provided templates for different pluralization rules.
    • createPluralizationRules(): Generates a list of PluralizationRule instances from provided templates.
    • PluralizationTemplates Interface: Defines templates for various quantities and converts them into a list of rules.

@teogor teogor added @documentation Improvements or additions to documentation @enhancement New feature or request labels Aug 28, 2024
@teogor teogor added this to the 1.0.0-alpha02 milestone Aug 28, 2024
@teogor teogor self-assigned this Aug 28, 2024
@teogor teogor merged commit c657e2e into main Aug 28, 2024
4 checks passed
@zeobot zeobot bot deleted the feature/plurals-enhancement branch August 28, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@documentation Improvements or additions to documentation @enhancement New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

1 participant