{"id":16831,"library":"i18n-t","title":"i18n-t","description":"i18n-t is a minimalist internationalization (i18n) utility for JavaScript, offering a straightforward API to manage translations. Its current stable version is 1.0.1, last released in June 2016. The library focuses on simplicity, allowing developers to set a default locale, load translation messages from local files or pre-loaded JavaScript objects, and perform basic string translation with variable interpolation. Unlike more comprehensive and actively maintained solutions such as `i18next` or `i18n-js`, `i18n-t` explicitly avoids framework-specific integrations or advanced features like pluralization rules, context-sensitive translations, or backend loading mechanisms. Its key differentiator was its 'dumb' and easy-to-use nature, making it suitable for very basic i18n needs without external dependencies or complex configurations. However, due to its long-term abandonment, it lacks modern features like ESM support, TypeScript typings, and ongoing security updates.","status":"abandoned","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/SamyPesse/i18n-t","tags":["javascript"],"install":[{"cmd":"npm install i18n-t","lang":"bash","label":"npm"},{"cmd":"yarn add i18n-t","lang":"bash","label":"yarn"},{"cmd":"pnpm add i18n-t","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only and does not provide an ESM export. Direct `import` statements will fail.","wrong":"import I18n from 'i18n-t';","symbol":"I18n","correct":"const I18n = require('i18n-t');"},{"note":"The primary translation function `t` is a method on an `I18n` instance, requiring the locale and key as explicit arguments.","symbol":"i18n.t","correct":"const i18n = new I18n({ defaultLocale: 'en' }); i18n.t('en', 'HELLO', { name: 'World' });"},{"note":"Used to load translation files from a specified directory. Ensure the path is correct for your environment (e.g., Node.js `__dirname`).","symbol":"i18n.load","correct":"const i18n = new I18n({ defaultLocale: 'en' }); i18n.load('./locales');"}],"quickstart":{"code":"const I18n = require('i18n-t');\nconst path = require('path');\nconst fs = require('fs');\n\n// Create a dummy 'locales' directory and files for demonstration\nconst localesDir = path.join(__dirname, 'temp_locales');\nif (!fs.existsSync(localesDir)) {\n  fs.mkdirSync(localesDir);\n}\nfs.writeFileSync(path.join(localesDir, 'en.js'), 'module.exports = { HELLO: \"Hello {{name}}\", CATS: \"{{0}} cats\", DOGS: \"No dogs\" };');\nfs.writeFileSync(path.join(localesDir, 'fr.js'), 'module.exports = { HELLO: \"Bonjour {{name}}\", CATS: \"{{0}} chats\" };');\n\nconst i18n = new I18n({\n    defaultLocale: 'en'\n});\n\n// Load locales from the dummy directory\ni18n.load(localesDir);\n\n// Or using a pre-loaded object (can be used alongside or instead of load)\ni18n.set({\n    es: {\n        HELLO: 'Hola {{name}}'\n    }\n});\n\n// Translate sentences\nconsole.log(i18n.t('en', 'HELLO', { name: 'Samy' }));\nconsole.log(i18n.t('en', 'CATS', 10));\nconsole.log(i18n.t('fr', 'HELLO', { name: 'Marie' }));\nconsole.log(i18n.t('fr', 'CATS', 5));\nconsole.log(i18n.t('es', 'HELLO', { name: 'Pedro' }));\nconsole.log(i18n.t('en', 'DOGS'));\nconsole.log(i18n.t('fr', 'DOGS')); // Will return key if not found in 'fr'\n\n// Clean up dummy directory (optional, for a runnable example)\nfs.unlinkSync(path.join(localesDir, 'en.js'));\nfs.unlinkSync(path.join(localesDir, 'fr.js'));\nfs.rmdirSync(localesDir);\n","lang":"javascript","description":"This quickstart demonstrates how to initialize `i18n-t`, load locales from a directory and pre-loaded objects, and then translate strings using the `t` method, including interpolation for variables and indexed placeholders."},"warnings":[{"fix":"Migrate to a actively maintained internationalization library like `i18next`, `i18n-js`, or `node-i18n` for better long-term support, features, and security.","message":"The `i18n-t` package has been abandoned since its last update in June 2016 (version 1.0.1). It receives no further development, bug fixes, or security updates. This poses significant risks for production applications.","severity":"breaking","affected_versions":"<=1.0.1"},{"fix":"Continue using `const I18n = require('i18n-t');` in CommonJS contexts. For projects requiring ESM, consider using a different, modern i18n library that explicitly supports ESM.","message":"This library is CommonJS-only and does not provide ES Module (ESM) exports. Attempting to use `import` syntax will result in module resolution errors in modern JavaScript environments.","severity":"gotcha","affected_versions":"<=1.0.1"},{"fix":"Create a `declare module 'i18n-t' { ... }` block with appropriate types for the `I18n` class and its methods, or migrate to a TypeScript-first i18n library.","message":"The package does not ship with TypeScript type definitions. Integrating it into a TypeScript project will require manually creating declaration files (e.g., `i18n-t.d.ts`) to avoid type errors.","severity":"gotcha","affected_versions":"<=1.0.1"},{"fix":"Implement custom logic to check for translation existence before calling `i18n.t` or wrap `i18n.t` with a function that provides desired fallback behavior. Ensure all required keys exist in your locale files.","message":"When a translation key is not found for a given locale, `i18n-t` defaults to returning the translation key itself. This behavior might be unexpected compared to other libraries that offer fallback locales or explicit `missingTranslationHandler` functions.","severity":"gotcha","affected_versions":"<=1.0.1"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Instantiate the I18n class using the `new` keyword: `const i18n = new I18n({ defaultLocale: 'en' });`","cause":"Attempting to call `I18n()` as a function instead of using `new I18n()`.","error":"TypeError: I18n is not a constructor"},{"fix":"This package is CommonJS. Ensure you are using `const I18n = require('i18n-t');` and that your project is configured for CommonJS, or migrate to an i18n library that supports ESM.","cause":"Trying to `require()` an ES Module or `import` a CommonJS module in an incompatible environment or without proper transpilation.","error":"Error: require() of ES Module [...] not supported."},{"fix":"Run `npm install i18n-t` to ensure the package is installed. If in an ESM project, consider using a different i18n library or a CJS-to-ESM wrapper if absolutely necessary, though migration is recommended.","cause":"The package is not installed or the `node_modules` directory is not correctly resolved, or trying to `import` in a pure ESM context that doesn't understand CJS.","error":"Cannot find module 'i18n-t' or similar module resolution error"}],"ecosystem":"npm","meta_description":null}