i18next
Internationalization framework with translation lookup, pluralization, interpolation and language detection.
Official Documentation ↗i18next v23.x / Node 18 LTS 与浏览器. Check the official docs for the latest API surface.Installation
npm install i18nextpnpm add i18nextyarn add i18nextMethods
No methods match this filter.
Overview
i18next is an internationalization framework that resolves translation keys to localized strings, handling interpolation, pluralization and namespaces across many languages.
Core Methods
init registers languages and resources, t looks up keys with options for interpolation and count, and changeLanguage switches the active language. The React binding connects a hook to the instance.
Usage Notes
Organize resources by namespace, centralize keys in constants to catch typos, and configure detection carefully so crawlable pages do not redirect unexpectedly.
Common Pitfalls
Missing keys fall back to the key string, which can ship raw identifiers to users. Plural forms differ per language, so naive suffix assumptions break non-English locales. Interpolated values must be escaped when rendered as HTML.
FAQ
- What is a namespace?
- Namespaces split translation resources into files or groups, such as common and errors, so large apps load only what a view needs. Reference them with the ns option.
- How does pluralization work?
- Keys use suffixes like _one and _other, and i18next selects the right form from the count option according to the language plural rules. Each language may define different plural categories.
- How do I detect the user language?
- Use a detection plugin that reads the query string, cookies, localStorage and navigator language. Detection should be configured so crawlers receive stable server-rendered content rather than redirects.
Report a problem with this API docOpens a pre-filled issue on GitHub.