![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
i18next-typescript
Advanced tools
3�BB$6A/߷J arѡ��N! ���{��E�8QX�v���x��ڝP�{���� 2�R�p��4�y0��K9���M��_"���N��3�E������`�P��%��0�]��:��V�TI� �/+@;�11p;R]�O�"� �1�}˽?�l �Z� � ��M�ؽ�:>�����z�B��� (�-Y����$�Xn�qҝ��0j�>��=�P*�\}P!���E'�D
Stronger type support for i18-next
TFunction
to provide strong type support for translation keys.Usage: i18next-typescript generate|g [options]
Generate type definitions for all your translation keys.
Options:
-i, --in [inFolder] Path to a folder with your translation files
-o, --out [outFile] Path to the output file
--default-namespace [defaultNamespace] Default Namespace in your i18next configuration (default: "translation")
--indent [indent] Indentation level of output file (default: "2")
--type-name [typeName] Exported type name in the generated file (default: "TranslationKeys")
--quote-char [quoteChar] Character to use to quote strings (default: "'")
-c, --config [configFile] Path to config file (default: "i18next-typescript.config.json")
-h, --help display help for command
Usage: i18next-typescript watch|w [options]
Watch your translation files and generate type definitions for all your translations keys when they change.
Options:
-i, --in [inFolder] Path to a folder with your translation files
-o, --out [outFile] Path to the output file
--default-namespace [defaultNamespace] Default Namespace in your i18next configuration (default: "translation")
--indent [indent] Indentation level of output file (default: "2")
--type-name [typeName] Exported type name in the generated file (default: "TranslationKeys")
--quote-char [quoteChar] Character to use to quote strings (default: "'")
-c, --config [configFile] Path to config file (default: "i18next-typescript.config.json")
-h, --help display help for command
While all options can be provided through the command line, it's recommended to use a configuration file like the one below in your root folder:
{
"inFolder": "public/locales/en",
"outFile": "app/src/i18next.keys.ts",
"defaultNs": "translation",
"indent": 2,
"typeName": "TranslationKeys",
"quoteChar": "'"
}
Only inFolder
and outFile
are required. Minimal configuration:
{
"inFolder": "public/locales/en",
"outFile": "app/src/i18next.keys.ts",
}
To leverage the auto-generated types, override and re-export the TFunction
and/or WithT
.
// e.g. /app/src/i18next-overrides.ts
import { TypedTFunction } from "i18next-typescript";
import { TranslationKeys } from "./i18next.keys.ts";
export type TFunction = TypedTFunction<TranslationKeys>;
// e.g. /app/src/index.ts
import { TFunction } from "./i18next-overrides.ts";
// calling 't' will now autocomplete and complain if you use a key which doesn't exist
const greeting = (t: TFunction) => t("common:greeting.evening");
Run i18next-typescript
watch to automatically update the auto-generated types whenever you make changes to your translation files.
yarn
or npm install
yarn example:watch
or npx run example:watch
example/locales
example/i18next.keys.d.ts
FAQs
3�BB$6A/߷J arѡ��N! ���{��E�8QX�v���x��ڝP�{���� 2�R�p��4�y0��K9���M��_"���N��3�E������`�P��%��0�]��:��V�TI� �/+@;�11p;R]�O�"� �1�}˽?�l �Z� � ��M�ؽ�:>�����z�B��� (�-Y����$�Xn�qҝ��0j�>��=�P*�\}P!���E'�D
The npm package i18next-typescript receives a total of 84 weekly downloads. As such, i18next-typescript popularity was classified as not popular.
We found that i18next-typescript demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.