Skip to content

rewindbitcoin/i18n

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

i18n

This package provides a simple way to manage your i18n (internationalization) files for projects using i18next and react-i18next. It automates the creation of a locales directory, the generation of an init.ts entry file and a locales.ts file that aggregates all detected locales.

Installation

To get started, install the necessary packages using npm:

npm install @rewindbitcoin/i18n --save-dev
npm install i18next@25 react-i18next@16

Packages i18next@25 and react-i18next@16 are the latest versions known to work well with the code this tool generates. You should install them as regular dependencies (not dev dependencies) in your project.

Basic Usage

First, generate the initial locales folder and template files:

npx i18n_rewbtc

This command creates the ./i18n-locales directory in your project root. Place your translation files in this directory, using the .js format for each locale (e.g., en.js, es.js).

After adding your translation files, run the command again to generate the init.ts and locales.ts files:

npx i18n_rewbtc

These files are created in the ./i18n-locales directory. init.ts serves as the entry point for initializing i18next with your translations and locales.ts exports an array of all locales you've provided.

Importing Generated Files

You can import and use the generated initReactI18next function in your project like this:

import { initReactI18next } from './i18n-locales/init';
await initReactI18next('en'); // Initialize i18next with the 'en' locale

Advanced Usage

If your project structure includes a specific source directory for your translation files, you can specify this directory as an argument to the command:

npx i18n_rewbtc srcDirectory

Replace srcDirectory with the path to your source directory, relative to the current working directory. This argument allows the tool to correctly locate your translation files if they are not in the project root.

Note: If you provide an invalid directory or if the specified directory does not exist, the command will throw an error.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors