npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

i18n-file-generator

v1.0.0

Published

A Node.js module for generating i18n translation files effortlessly. It simplify i18n translation file management.

Downloads

6

Readme

i18n-file-generator

NPM Version NPM Downloads GitHub release License GitHub Pull Requests

This Node.js module simplifies i18n translation file management, making it effortless to generate and manage multiple translation files. It streamlines the localization process, providing an efficient and convenient solution for your projects.

Installation

npm install i18n-file-generator

yarn add i18n-file-generator

pnpm add i18n-file-generator

npx i18n-file-generator 

npx i18n-file-generator --config=your_config_file --provider=AWS --accessKeyId=your_accessKeyId --secretAccessKey=your_secretAccessKey

Note: If you have installed it globally, you can use the following command. You can choose your preferred package manager, whether it's npm, yarn, or pnpm; the choice is yours.


npm i18n-file-generator 

npm i18n-file-generator --config=your_config_file --provider=AWS --accessKeyId=your_accessKeyId --secretAccessKey=your_secretAccessKey

Note: You can pass additional parameters but these are optional. It will override the value of the config file.

  • --config=your_config_file
  • --provider=AWS
  • --accessKeyId=your_accessKeyId
  • --secretAccessKey=your_secretAccessKey

Usages

Folder structure:

+-- node_modules
+-- src
|   +-- index.js
|   +-- file1.js
|   +-- file1.js
+---locale
|   +-- en.json
| 
+-- package.json
+-- package-lock.json
+-- i18n.config.js
+-- README.md

If you'd like to generate multiple language files, such as 'hi.json,' 'es.json,' and 'fr.json' from your 'en.json,' please follow the examples below.

Example 1:

npx i18n-file-generator
// i18n.config.js

/** @type {import('i18n-file-generator').Config} */

module.exports = {
  provider: "AWS",
  accessKeyId: "YOUR_ACCESS_KEY",
  secretAccessKey: "YOUR_SECRET_ACCESS_KEY",
  awsRegion: "YOUR_REGION",                             // (optional) : Default = us-east-1
  sourceLanguageCode: "en"                              // Input language ISO code.
  targetLanguageCodes: ["fr", "hi", "es", "ru",'ja'],   // Output language ISO code list.
  sourceLanguageFilePath: "./locale/en.json",           // Input language file path                    
};

/**
 *It will generate JSON files for multiple languages within the 'locale' directory. 
 */

In that case, the folder structure will resemble the following:

+-- node_modules
+-- src
|   +-- index.js
|   +-- file1.js
|   +-- file1.js
+---locale
|   +-- en.json
|   +-- fr.json
|   +-- hi.json
|   +-- es.json
|   +-- ru.json
|   +-- js.json
| 
+-- package.json
+-- package-lock.json
+-- i18n.config.js
+-- README.md

Example 2:

If you wish to generate the output in a different directory, simply provide the 'outputDirectory' path

npx i18n-file-generator

// i18n.config.js

/** @type {import('i18n-file-generator').Config} */

module.exports = {
  provider: "AWS",
  accessKeyId: "YOUR_ACCESS_KEY",
  secretAccessKey: "YOUR_SECRET_ACCESS_KEY",
  awsRegion: "YOUR_REGION",                             // (optional) : Default = us-east-1
  sourceLanguageCode: "en"                              // Input language ISO code.
  targetLanguageCodes: ["fr", "hi", "es", "ru",'ja'],   // Output language ISO code list.
  sourceLanguageFilePath: "./locale/en.json",           // Input language file path
  outputDirectory: './i18n'                             // Output folder path
};

/**
 *It will generate multiple lanaguage json file in the i18n directory. 
 */

In that case, the folder structure will resemble the following:

+-- node_modules
+-- src
|   +-- index.js
|   +-- file1.js
|   +-- file1.js
|
+---locale
|   +-- en.json
|
+---118n
|   +-- en.json
|   +-- fr.json
|   +-- hi.json
|   +-- es.json
|   +-- ru.json
|   +-- js.json
| 
+-- package.json
+-- package-lock.json
+-- i18n.config.js
+-- README.md

Example 3:

If you want to pass secrets as external parameters, simply provide the additional arguments.

npx i18n-file-generator --secretAccessKey=YOUR_ACCESS_KEY --secretAccessKey=YOUR_SECRET_ACCESS_KEY

This functionality proves invaluable for generating translation files within the CI/CD environment.

npx i18n-file-generator --secretAccessKey=${{ secrets.AWS_ACCESS_KEY }} --secretAccessKey=${{ secrets.AWS_ACCESS_SSECRET_KEY }}
// i18n.config.js

/** @type {import('i18n-file-generator').Config} */

module.exports = {
  provider: "AWS",
  awsRegion: "YOUR_REGION",                             // (optional) : Default = us-east-1
  sourceLanguageCode: "en"                              // Input language ISO code.
  targetLanguageCodes: ["fr", "hi", "es", "ru",'ja'],   // Output language ISO code list.
  sourceLanguageFilePath: "./locale/en.json",           // Input language file path                    
};

/**
 *It will generate JSON files for multiple languages within the 'locale' directory. 
 */

In that case, the folder structure will resemble the following:

+-- node_modules
+-- src
|   +-- index.js
|   +-- file1.js
|   +-- file1.js
+---locale
|   +-- en.json
|   +-- fr.json
|   +-- hi.json
|   +-- es.json
|   +-- ru.json
|   +-- js.json
| 
+-- package.json
+-- package-lock.json
+-- i18n.config.js
+-- README.md

Example 4:

Within the GitHub Action triggered upon a push to the 'master' branch, we have the capability to generate and update multiple translation files.


# ci.yml

name: CI workflow

on:
    push:
        branches: [master]

jobs:
    build:
        name: "Building source code"
        runs-on: ubuntu-latest
        strategy:
            matrix:
                node-version: [18.x]
        steps:
            - uses: actions/checkout@v3
            - name: Use Node.js ${{ matrix.node-version }}
              uses: actions/setup-node@v3
              with:
                  node-version: ${{ matrix.node-version }}
                  cache: "npm"
            - run: npm install
            - run: npx i18n-file-generator --secretAccessKey=${{ secrets.AWS_ACCESS_KEY }} --secretAccessKey=${{ secrets.AWS_ACCESS_SSECRET_KEY }}    
            - run: npm run build
            - run: npm run test

# Please note that you should execute this command immediately after npm installation to prevent any potential disruptions, especially if you are utilizing test cases.
// i18n.config.js

/** @type {import('i18n-file-generator').Config} */

module.exports = {
  provider: "AWS",
  awsRegion: "YOUR_REGION",                             // (optional) : Default = us-east-1
  sourceLanguageCode: "en"                              // Input language ISO code.
  targetLanguageCodes: ["fr", "hi", "es", "ru",'ja'],   // Output language ISO code list.
  sourceLanguageFilePath: "./locale/en.json",           // Input language file path                    
};

/**
 * Note: Note: The configuration file should be in the root directory of your project. If it's in a different location, you have to specify it, as failing to do so may lead to runtime errors.
 * 
 *It will generate JSON files for multiple languages within the 'locale' directory. 
 */

In that case, the folder structure will resemble the following:

+-- node_modules
+-- src
|   +-- index.js
|   +-- file1.js
|   +-- file1.js
+---locale
|   +-- en.json
|   +-- fr.json
|   +-- hi.json
|   +-- es.json
|   +-- ru.json
|   +-- js.json
| 
+-- package.json
+-- package-lock.json
+-- i18n.config.js
+-- README.md

Example 4:

When using this package as a function method in your code, follow these steps:


const { TranslationManager } = require("i18n-file-generator");

const translationMAnager = new TranslationManager({
  awsRegion: "ap-south-1",
  accessKeyId: process.env.AWS_ACCESS_KEY,
  secretAccessKey: process.env.AWS_ACCESS_SSECRET_KEY,
  provider: "AWS",
});


translationMAnager.translateI18n({
  sourceLanguageCode: "en",
  targetLanguageCodes:   ["fr", "hi", "es", "ru"],
  sourceLanguageFilePath: "./locale/en.json",
  outputDirectory: './i18n'                         // (optional)
});

/**
 * 
 * The default output directory is set to the location of your input 'sourceLanguageFilePath' file, where all the generated translation files will be stored.
 * 
 * /

Contributors

License

MIT

Free Software