i18next documentation
🏠 i18next🌐 localization as a service🎓 i18next crash course💾 GitHub Repository
  • Introduction
  • Overview
    • Getting started
    • Comparison to others
    • API
    • Configuration Options
    • Supported Frameworks
    • Plugins and Utils
    • For Enterprises
    • First setup help
    • TypeScript
  • Translation Function
    • Essentials
    • Interpolation
    • Formatting
    • Plurals
    • Nesting
    • Context
    • Objects and Arrays
  • Principles
    • Best Practices
    • Translation Resolution
    • Namespaces
    • Fallback
    • Plugins
  • How to
    • Add or Load Translations
    • Extracting translations
    • Caching
    • Backend Fallback
    • FAQ
  • Misc
    • JSON Format
    • Creating own Plugins
    • Migration Guide
    • The history of i18next
    • Testimonials
  • 🌐localization as a service
  • 🎓i18next crash course
  • 💾GitHub Repository
Powered by GitBook
On this page
  • Basic
  • Combining with plurals
  1. Translation Function

Context

Last updated 2 years ago

By providing a context you can differ translations. Eg. useful to provide gender specific translations.

🎓 Check out this topic in the .

Basic

keys

{
      "friend": "A friend",
      "friend_male": "A boyfriend",
      "friend_female": "A girlfriend"
}

sample

i18next.t('friend'); // -> "A friend"
i18next.t('friend', { context: 'male' }); // -> "A boyfriend"
i18next.t('friend', { context: 'female' }); // -> "A girlfriend"

Combining with plurals

You can pass entire data models in options.

keys

{
      "friend_male_one": "A boyfriend",
      "friend_female_one": "A girlfriend",
      "friend_male_other": "{{count}} boyfriends",
      "friend_female_other": "{{count}} girlfriends"
}

sample

i18next.t('friend', {context: 'male', count: 1}); // -> "A boyfriend"
i18next.t('friend', {context: 'female', count: 1}); // -> "A girlfriend"
i18next.t('friend', {context: 'male', count: 100}); // -> "100 boyfriends"
i18next.t('friend', {context: 'female', count: 100}); // -> "100 girlfriends"
i18next crash course video