Registry / developer-tools / i18next-cli-language-detector

i18next-cli-language-detector

JSON →
library1.1.8jsnpmunverified

i18next third-party language detector for CLI applications. It detects the user's language from environment variables (LC_ALL, LC_MESSAGES, LANG, LANGUAGE) following the GNU Gettext convention. Current stable version is 1.1.8. It ships TypeScript types and requires i18next as a peer dependency. Ideal for command-line tools using i18next that need locale detection from the system environment. Unlike browser or Express detectors, this targets Node.js CLI environments.

npm install i18next-cli-language-detector
INSTALL
IMPORT
SIG · I18NEXT-CLI-LANGUA
I
i18next-cli-language-detector
developer-toolsjavascriptv1.1.8
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

I18nextCLILanguageDetector
import I18nextCLILanguageDetector from 'i18next-cli-language-detector'
const I18nextCLILanguageDetector = require('i18next-cli-language-detector')
ESM package; use import syntax. CJS require works but is not preferred.
I18nextCLILanguageDetector
import i18next from 'i18next'; import I18nextCLILanguageDetector from 'i18next-cli-language-detector'; i18next.use(I18nextCLILanguageDetector)
i18next.use(I18nextCLILanguageDetector) before import or without calling .use()
You must call .use(I18nextCLILanguageDetector) before .init()
type I18nextCLILanguageDetector
import type { default as I18nextCLILanguageDetector } from 'i18next-cli-language-detector'
import type I18nextCLILanguageDetector from 'i18next-cli-language-detector'
TypeScript type import requires the default import pattern. The package exports a class.

Shows how to initialize i18next with the CLI language detector, providing resources for English and German and falling back to English.

import i18next from 'i18next'; import I18nextCLILanguageDetector from 'i18next-cli-language-detector'; i18next .use(I18nextCLILanguageDetector) .init({ fallbackLng: 'en', resources: { en: { translation: { greeting: 'Hello' } }, de: { translation: { greeting: 'Hallo' } } } }); console.log(i18next.t('greeting')); // Uncomment to test with environment variable: // process.env.LANG = 'de_DE.UTF-8'; // It will print 'Hallo'
Debug
Known issues
gotchaThe detector only reads environment variables per GNU Gettext conventions; it does not support command-line flags like --lang or --locale.
fix
If you need CLI flag support, parse it yourself and set i18next language via i18next.changeLanguage(lang) after initialization.
affects: >=0.0.0
gotchaThe detector uses synchronous environment variable checks; if you call i18next.t before init completes, the detector may not have run.
fix
Ensure i18next is initialized via async init() or use i18next.t inside a callback/after promise.
affects: >=0.0.0
deprecatedNo known deprecations in version 1.1.8.
fix
N/A
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: I18nextCLILanguageDetector is not a constructor
Trying to instantiate the detector directly (e.g., new I18nextCLILanguageDetector()) instead of passing the class to i18next.use().
fix
Remove 'new' keyword: i18next.use(I18nextCLILanguageDetector)
Error: Cannot find module 'i18next-cli-language-detector'
Package not installed or installed without i18next peer dependency.
fix
Run 'npm install i18next i18next-cli-language-detector'
i18next: languageDetector is not a function
Calling .use() after .init() or not calling .use() at all.
fix
Chain .use() before .init(): i18next.use(detector).init()
Upgrade
Version history
1.1.8latest on npm
Audit
Dependencies
i18nextrequiredpeer dependency; language detector is meant to be used with i18next
Agent activity
55 hits · last 30 days
node
47
Resources
i18next-cli-language-detector — npm install i18next-cli-language-detector · libregistry