i18next-parser-workspaces
v0.2.1
Published
Run i18next-parser over all source files in your TypeScript project
Downloads
721
Readme
i18next Parser Workspaces Utilities
i18next-workspaces is a Node.js tool designed to simplify the process of internationalization (i18n) for TypeScript projects using i18next-parser. It scans your project's source files based on your TypeScript configuration, allowing it to seamlessly work within project workspaces without the need for configuring i18next-parser to scan absolute file paths within the workspace.
References
- https://github.com/i18next/i18next-parser
- https://github.com/prettier/prettier
Features
- Automatic Scanning: Automatically scans all source files within your TypeScript project based on your project's tsconfig.json file.
- Configurability: Customize i18next-parser behavior using your own configuration file.
- Resource File Generation: Generate a resources file that exports all namespaces for easy reference.
- Prettier Integration: Optionally use a Prettier configuration file to ensure consistent code formatting.
- Verbose Logging: Enable additional logging for more insight into the scanning process.
Installation
Install i18next-parser-workspaces in your project using:
npm install -D i18next-parser-workspaces
yarn add -D i18next-parser-workspaces
Project
The target project should have a tsconfig.json and i18next configuration.
Usage
To print information about the commands in your terminal run:
$ i18next-workspaces --help
Commands
Parse
The parse command scans all source files and generate i18n translation files in your projects directory.
$ i18next-workspaces parse [options] <projectPath>
$ i18next-workspaces parse --verbose ./packages/frontend
Options
--config <file>
: path to your i18next-parser config (default: i18next-parser.config.[js,mjs])--verbose
: enable additional logging for debugging purposes.--h, --help
: display help for command
Namespaces
The namespaces command generates a resources.ts
file that exports all namespaces as string.
$ i18next-workspaces namespaces [options] <projectPath> [outputFile]
$ i18next-workspaces namespaces --verbose ./packages/frontend ./src/i18n/resources.ts
Options
--config <file>
: path to your i18next-parser config (default: i18next-parser.config.[js,mjs])--locale <locale>
: specify the locale to look for namespaces (defaults: first found locale).--prettier <config>
: specify the path to the Prettier configuration file (default: ".prettierrc").--verbose
: enable additional logging for debugging purposes.--h, --help
: display help for command
Fill missing
The fill-missing command fills missing (empty) translations using values from the source project.
$ i18next-workspaces fill-missing [options] <projectA> <projectB>
$ i18next-workspaces fill-missing --verbose ./packages/frontend ./packages/app
Options
--configA <file>
: path to your i18next-parser config for projectA (default: i18next-parser.config.[js,mjs])--configB <file>
: path to your i18next-parser config for projectB (default: i18next-parser.config.[js,mjs])--verbose
: enable additional logging for debugging purposes.--h, --help
: display help for command
Examples
This command will parse all source files and generate the translation files.
i18next-workspaces parse ./path/to/project
This command will scan all TypeScript files in the "src" directory of your project, generate a resources file for the "en" locale, and export all namespaces.
i18next-workspaces namespaces ./path/to/project ./src/i18n/namespaces.ts --locale en
Example output of the namespaces.ts file:
// This file is generated by i18next-parser-workspaces, do not modify manually.
// Run `$ npx i18next-workspaces` to update this file
export const NAMESPACES = ['common', 'namespace2', 'ns3'];
License
This project is licensed under the MIT License. See the LICENSE file for details.