Back to Blog

Pluralization Rules in i18next: Handle Complex Grammar Across Languages

Master i18next pluralization rules for complex languages. Learn to handle multiple plural forms, gender agreement, and advanced grammar rules in your internationalized applications.

Posted by

i18next pluralization rules guide

Table of Contents

Understanding Pluralization in i18next

Pluralization is one of the most challenging aspects of internationalization. While English has relatively simple plural rules (singular/plural), many languages have complex pluralization systems with multiple forms based on quantity, gender, and grammatical context.

i18next provides robust pluralization support that handles the complexity of different languages automatically. Understanding these patterns is crucial for creating truly international applications that feel natural to native speakers.

Language Pluralization Complexity

LanguagePlural FormsComplexity
English2 (one, other)Simple
Russian3 (one, few, many)Medium
Polish4 (one, few, many, other)Complex
Arabic6 (zero, one, two, few, many, other)Very Complex

Basic Pluralization Patterns

English Pluralization

English uses a simple two-form system (singular/plural):

// en/translation.json
{
  "item": "{{count}} item",
  "item_other": "{{count}} items",
  
  // Alternative key-based syntax
  "book": {
    "one": "{{count}} book",
    "other": "{{count}} books"
  }
}

Usage in Components

import { useTranslation } from 'react-i18next';

function ItemCounter({ count }) {
  const { t } = useTranslation();
  
  return (
    <div>
      <p>{t('item', { count })}</p>
      <p>{t('book', { count })}</p>
    </div>
  );
}

// Output examples:
// count = 1: "1 item", "1 book"  
// count = 5: "5 items", "5 books"

Zero Handling

{
  "notification": {
    "zero": "No new notifications",
    "one": "{{count}} new notification", 
    "other": "{{count}} new notifications"
  }
}

Complex Pluralization Languages

Russian Pluralization (3 forms)

Russian has three plural forms based on the last digit of the number:

// ru/translation.json
{
  "day": {
    "one": "{{count}} день",     // 1, 21, 31, 41, ...
    "few": "{{count}} дня",      // 2-4, 22-24, 32-34, ...
    "many": "{{count}} дней"     // 0, 5-20, 25-30, ...
  },
  "file": {
    "one": "{{count}} файл",
    "few": "{{count}} файла", 
    "many": "{{count}} файлов"
  }
}

Polish Pluralization (4 forms)

// pl/translation.json  
{
  "person": {
    "one": "{{count}} osoba",      // 1
    "few": "{{count}} osoby",      // 2-4, 22-24, 32-34, ...
    "many": "{{count}} osób",      // 0, 5-21, 25-31, ...
    "other": "{{count}} osoby"     // fractional numbers
  }
}

Arabic Pluralization (6 forms)

// ar/translation.json
{
  "message": {
    "zero": "لا توجد رسائل",           // 0
    "one": "رسالة واحدة",            // 1  
    "two": "رسالتان",               // 2
    "few": "{{count}} رسائل",        // 3-10
    "many": "{{count}} رسالة",       // 11-99
    "other": "{{count}} رسالة"       // 100+, fractional
  }
}

Custom Pluralization Rules

For languages not covered by i18next's built-in rules, you can define custom pluralization:

// Custom pluralization rule example
i18next.init({
  pluralSeparator: '_',
  pluralResolver: {
    addRule: (lng, obj) => {
      // Custom rule for a fictional language
      obj.rules[lng] = {
        numbers: [0, 1, 2],
        plurals: function(n) {
          if (n === 0) return 0; // zero form
          if (n === 1) return 1; // singular form  
          return 2; // plural form
        }
      };
    }
  }
});

Advanced Pluralization Techniques

Ordinal Numbers

{
  "ordinal": {
    "one": "{{count}}st",    // 1st, 21st, 31st
    "two": "{{count}}nd",    // 2nd, 22nd, 32nd  
    "few": "{{count}}rd",    // 3rd, 23rd, 33rd
    "other": "{{count}}th"   // 4th, 5th, 6th, ...
  }
}

Context-Aware Pluralization

// Different pluralization based on context
{
  "user": {
    "online": {
      "zero": "No users online",
      "one": "{{count}} user online",
      "other": "{{count}} users online"
    },
    "registered": {
      "zero": "No registered users", 
      "one": "{{count}} registered user",
      "other": "{{count}} registered users"
    }
  }
}

// Usage with context
t('user.online', { count: 5 }); // "5 users online"
t('user.registered', { count: 1 }); // "1 registered user"

Nested Pluralization

{
  "comment": {
    "reply": {
      "zero": "No replies",
      "one": "{{count}} reply", 
      "other": "{{count}} replies"
    },
    "like": {
      "zero": "No likes",
      "one": "{{count}} like",
      "other": "{{count}} likes" 
    }
  }
}

// Complex usage
const CommentStats = ({ replies, likes }) => {
  return (
    <div>
      <span>{t('comment.reply', { count: replies })}</span>
      <span>{t('comment.like', { count: likes })}</span>
    </div>
  );
};

Gender Agreement and Grammatical Cases

Many languages require gender agreement and grammatical case changes in plural forms:

German Gender Agreement

// de/translation.json
{
  "friend": {
    "male": {
      "one": "{{count}} Freund",
      "other": "{{count}} Freunde"
    },
    "female": { 
      "one": "{{count}} Freundin",
      "other": "{{count}} Freundinnen"
    }
  }
}

// Usage with gender context
t('friend.male', { count: 2 });   // "2 Freunde"
t('friend.female', { count: 2 }); // "2 Freundinnen"

Czech Grammatical Cases

// cs/translation.json  
{
  "book": {
    "nominative": {
      "one": "{{count}} kniha",    // subject
      "few": "{{count}} knihy", 
      "other": "{{count}} knih"
    },
    "accusative": {
      "one": "{{count}} knihu",    // direct object
      "few": "{{count}} knihy",
      "other": "{{count}} knih" 
    }
  }
}

Dynamic Gender Selection

// Component with gender-aware pluralization
const UserProfile = ({ user, friendCount }) => {
  const { t } = useTranslation();
  const genderKey = user.gender === 'female' ? 'female' : 'male';
  
  return (
    <div>
      <h2>{user.name}</h2>
      <p>{t(`friend.${genderKey}`, { count: friendCount })}</p>
    </div>
  );
};

Testing and Validation

Pluralization Test Suite

// Test different plural forms
const testPluralization = (key, language, testCases) => {
  i18next.changeLanguage(language);
  
  testCases.forEach(({ count, expected }) => {
    const result = i18next.t(key, { count });
    console.assert(
      result === expected,
      `Failed for ${language}, count: ${count}. Expected: ${expected}, Got: ${result}`
    );
  });
};

// Test cases for different languages
testPluralization('item', 'en', [
  { count: 0, expected: '0 items' },
  { count: 1, expected: '1 item' },
  { count: 2, expected: '2 items' }
]);

testPluralization('день', 'ru', [
  { count: 1, expected: '1 день' },
  { count: 2, expected: '2 дня' }, 
  { count: 5, expected: '5 дней' },
  { count: 21, expected: '21 день' }
]);

Automated Validation

// Validate all plural forms exist
const validatePluralCompleteness = (translations, language) => {
  const pluralRules = i18next.services.pluralResolver.getRule(language);
  const requiredForms = pluralRules.numbers;
  
  Object.keys(translations).forEach(key => {
    if (typeof translations[key] === 'object') {
      const availableForms = Object.keys(translations[key]);
      
      requiredForms.forEach(form => {
        const formName = pluralRules.plurals(form);
        if (!availableForms.includes(formName)) {
          console.warn(`Missing plural form '${formName}' for key '${key}' in ${language}`);
        }
      });
    }
  });
};

AI-Generated Plural Translations

Creating accurate plural forms manually for multiple languages is extremely time-consuming and error-prone. i18nowAI specializes in generating grammatically correct plural translations that handle complex pluralization rules automatically.

i18nowAI Pluralization Features

  • Automatic Rule Detection: Recognizes plural patterns in source translations
  • Grammar-Aware Translation: Generates correct forms for each target language
  • Context Preservation: Maintains semantic meaning across different plural forms
  • Gender Agreement: Handles masculine/feminine/neuter forms where applicable
  • Cultural Adaptation: Adapts numbers and quantities to local conventions

Example: AI-Generated Plurals

// Input (English)
{
  "message": {
    "zero": "No messages",
    "one": "{{count}} message",
    "other": "{{count}} messages"
  }
}

// AI-Generated Output (Russian)
{
  "message": {
    "one": "{{count}} сообщение",
    "few": "{{count}} сообщения", 
    "many": "{{count}} сообщений"
  }
}

// AI-Generated Output (Arabic)  
{
  "message": {
    "zero": "لا توجد رسائل",
    "one": "رسالة واحدة",
    "two": "رسالتان",
    "few": "{{count}} رسائل",
    "many": "{{count}} رسالة",
    "other": "{{count}} رسالة"
  }
}

Workflow with i18nowAI

  1. Create plural forms in your base language (typically English)
  2. Upload your i18next JSON files to i18nowAI
  3. Select target languages with complex pluralization rules
  4. AI automatically generates grammatically correct plural forms
  5. Download and integrate the translated files
  6. Test with various count values to verify correctness

Best Practices for Pluralization

  • Test Edge Cases: Always test with 0, 1, 2, and various numbers ending in different digits
  • Cultural Context: Consider cultural differences in number presentation
  • Gender Awareness: Account for gender agreement in languages that require it
  • Fallback Strategy: Provide fallback translations for unsupported plural forms
  • Automated Testing: Include pluralization in your automated test suite
  • Native Speaker Review: Have native speakers review complex plural forms

Conclusion

Mastering pluralization in i18next is essential for creating truly international applications. While the complexity varies significantly across languages, understanding these patterns enables you to build applications that feel natural to speakers of any language.

Combine i18next's powerful pluralization features with i18nowAI's AI-powered translation generation to automatically create grammatically correct plural forms across 30+ languages, saving countless hours of manual translation work while ensuring linguistic accuracy.

For more advanced internationalization topics, explore our guides on JSON translation best practices and choosing the right i18n framework.