{"id":47533,"library":"express-rest-i18n","title":"express-rest-i18n","description":"Dead simple i18n middleware for Express REST APIs. Version 1.0.1 provides lightweight, dependency-free internationalization with nested message support and automatic locale detection via query, header, or cookie. No build tools, no extra dependencies; simply define messages in JSON and use the `t()` method on `req` or `res`. Unlike heavier i18n libraries, it focuses solely on REST APIs with a minimal footprint. Released as stable, with no active development but no known issues.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/felippe-regazio/express-rest-i18n","tags":["javascript"],"install":[{"cmd":"npm install express-rest-i18n","lang":"bash","label":"npm"},{"cmd":"yarn add express-rest-i18n","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-rest-i18n","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency - middleware requires Express app","package":"express","optional":false}],"imports":[{"note":"ESM import using default export. CommonJS require also works as the package exports a single function.","wrong":"const i18nCreate = require('express-rest-i18n');","symbol":"default","correct":"import i18nCreate from 'express-rest-i18n';"},{"note":"CommonJS style - the package exports a single function as default; named import is incorrect.","wrong":"import { i18nCreate } from 'express-rest-i18n';","symbol":"i18nCreate","correct":"const i18nCreate = require('express-rest-i18n');"},{"note":"The `t()` method is available on `res.i18n` or `req.i18n`, not directly on `req` or `res`.","wrong":"const text = req.t('key');","symbol":"t() method on res/req","correct":"const text = res.i18n.t('key');"}],"quickstart":{"code":"import express from 'express';\nimport i18nCreate from 'express-rest-i18n';\n\nconst app = express();\n\nconst i18n = i18nCreate({\n  defaultLocale: 'en',\n  allowFallback: true,\n  messages: {\n    en: { greeting: 'Hello' },\n    'pt-br': { greeting: 'Olá' },\n  },\n});\n\napp.use(i18n.middleware);\n\napp.get('/', (req, res) => {\n  const msg = res.i18n.t('greeting');\n  res.send(msg);\n});\n\napp.listen(3000);","lang":"typescript","description":"Creates an i18n middleware, registers it, and uses the t() method in a route."},"warnings":[{"fix":"Ensure app.use(i18n.middleware) comes after app.use(bodyParser.json()) or similar.","message":"Middleware should be added after body-parser to recognize parsed body for locale detection.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use res.i18n.t('key') or req.i18n.t('key') instead of res.t('key') or req.t('key').","message":"The t() method is attached to res.i18n and req.i18n, not directly on res or req.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Check if the returned value equals the key to detect missing translations.","message":"When a key is not found, t() returns the key string itself, not an error or undefined.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure only one locale source is used or understand the priority: query > header > cookie > defaultLocale.","message":"Locale detection order: query param (locale), header (Accept-Language), then cookie (locale). Unknown behavior if multiple sources conflict.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set allowFallback: false if you want strict locale enforcement.","message":"allowFallback: true (default) means missing keys fall back to defaultLocale, not chain fallback through multiple locales.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.1':14 'activ':73 'api':12,63 'automat':26 'build':35 'cooki':33 'dead':5 'defin':41 'depend':18,39 'dependency-fre':17 'detect':28 'develop':74 'express':2,10 'express-rest-i18n':1 'extra':38 'focus':59 'footprint':67 'free':19 'header':31 'heavier':55 'i18n':4,7,56 'internation':20 'issu':78 'javascript':79 'json':44 'known':77 'librari':57 'lightweight':16 'local':27 'messag':23,42 'method':49 'middlewar':8 'minim':66 'nest':22 'provid':15 'queri':30 'releas':68 'req':51 'res':53 'rest':3,11,62 'simpl':6 'simpli':40 'sole':60 'stabl':70 'support':24 'tool':36 'unlik':54 'use':46 'version':13 'via':29","created_at":"2026-06-07T16:52:00.170322+00:00","updated_at":"2026-06-07T16:52:00.170322+00:00","problems":[{"fix":"Ensure app.use(i18n.middleware) is called after body-parser and before routes.","cause":"Middleware not added or added before body-parser, so res.i18n or req.i18n is undefined.","error":"Cannot read properties of undefined (reading 't')"},{"fix":"Use req.i18n.t('key') or res.i18n.t('key').","cause":"Attempting to call t() directly on req or res instead of req.i18n or res.i18n.","error":"t is not a function"},{"fix":"Use const i18nCreate = require('express-rest-i18n'); or add \"type\": \"module\" to package.json.","cause":"Using ESM import in a CommonJS project without proper configuration.","error":"import i18nCreate from 'express-rest-i18n'; SyntaxError: Cannot use import statement outside a module"},{"fix":"Use default import (import i18nCreate from ...) or const i18nCreate = require(...).","cause":"Incorrect import: using named import for a default export.","error":"module.exports = function(...) - TypeError: i18nCreate is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/felippe-regazio/express-rest-i18n#readme","github":"https://github.com/felippe-regazio/express-rest-i18n","docs":null,"changelog":null,"pypi":null,"npm":"express-rest-i18n","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}