ISO639 Language Codes
The `iso639-codes` package provides a comprehensive, static dataset of ISO639 language codes, mapping human-readable language names to their corresponding ISO639-1 (alpha-2) and ISO639-2 (alpha-3) codes, alongside a list of alternative names for each language. The current stable version is 1.0.1, indicating a mature and stable dataset. The package operates on a data-driven release cadence, likely receiving updates primarily when the underlying ISO standard data source (www.loc.gov/standards/iso639-2) changes, or for minor maintenance. Its key differentiator is its direct, pre-parsed JSON structure, which allows for straightforward integration and fast local lookups of language metadata, making it suitable for internationalization (i18n) efforts requiring efficient access to language identifier information without external API calls.
Common errors
-
TypeError: Cannot read properties of undefined (reading 'iso639-1')
cause The language key used to access the `iso` object does not exist, is misspelled, or incorrectly cased.fixEnsure the language name matches a key in the `iso` object exactly. Keys are case-sensitive. You can inspect `Object.keys(iso)` to see available language names. Example: `iso['Portuguese']`. -
SyntaxError: Named export 'iso' not found
cause Attempting to use a named import (`import { iso } from 'iso639-codes';`) when the module exports the entire dataset as a default.fixUse a default import statement: `import iso from 'iso639-codes';` -
ReferenceError: iso is not defined
cause The `iso` variable was used before it was properly imported or required from the package.fixEnsure `const iso = require('iso639-codes');` (for CommonJS) or `import iso from 'iso639-codes';` (for ESM) is at the top of your file before `iso` is referenced.
Warnings
- gotcha The language keys used to access data (e.g., 'Portuguese') are case-sensitive. Using incorrect casing will result in `undefined`.
- gotcha The `iso639-1` property might be `null` for some languages if a two-letter (alpha-2) code does not exist for that language.
- gotcha The package's data source (www.loc.gov/standards/iso639-2) and the package itself are static. While generally stable, rely on regular updates from the maintainer for the data to reflect the latest ISO standards.
Install
-
npm install iso639-codes -
yarn add iso639-codes -
pnpm add iso639-codes
Imports
- iso
import { iso } from 'iso639-codes';import iso from 'iso639-codes';
- iso (CommonJS)
const iso = require('iso639-codes'); - Language Data Access
iso.English.iso639-1
iso['English']['iso639-1']
Quickstart
import iso from 'iso639-codes';
// Accessing specific language data by name
console.log(`Portuguese ISO639-1: ${iso['Portuguese']['iso639-1']}`);
console.log(`Portuguese ISO639-2: ${iso['Portuguese']['iso639-2']}`);
// Some languages may not have an ISO639-1 code (returns null)
console.log(`Balinese ISO639-1: ${iso['Balinese']['iso639-1']}`); // Expected: null
// Accessing alternative names for a language
console.log(`Chichewa names: ${iso['Chichewa'].names.join(', ')}`);
// Iterating through the first few languages in the dataset
console.log('\n--- First 3 languages ---');
let count = 0;
for (const langName in iso) {
if (count >= 3) break;
const language = iso[langName];
console.log(`Name: ${language.name}, ISO639-1: ${language['iso639-1'] ?? 'N/A'}, ISO639-2: ${language['iso639-2']}`);
count++;
}
// Example of looking up a non-existent language (will be undefined)
const nonExistentLang = iso['Klingon'];
console.log(`\nKlingon data: ${nonExistentLang}`);