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

@stratupai/translation-tool

v1.0.8

Published

Tool to create locale translation files with Google Cloud Translate

Downloads

16

Readme

@stratupai/translation-tool

A command-line tool for generating translation files for i18next using the Google Cloud Translate API (Language Detection Model v2).

Implement Internationalization with the help of i18next.

Getting Started

Before using this tool, ensure you have enabled the Google Cloud Translation API and obtained the necessary credentials. Please refer to the Google Cloud Translation API Documentation for detailed instructions.

Step 1: Enable Google Cloud Translation API

  1. Go to Google Cloud Console.
  2. Select your project.
  3. Navigate to APIs & Services > Cloud Translation API.
  4. Enable the API.

Step 2: Obtain Credentials

  1. Create the access credentials as described in the Google Workspace documentation.
  2. Rename the credentials file to credentials.json.
  3. Place credentials.json in the root directory of your project.

For a detailed walkthrough, you can watch this video tutorial.

Step 3: Installation

Install the package via npm:

npm i @stratupai/translation-tool --save-dev

Step 4: Verify Installation

Type the following command in your terminal to check the default configuration:

translate

Usage

Default configuration:

{
  "localesPath": "public/locales",
  "credentialsPath": "credentials.json",
  "sourceLanguage": "en",
  "targetLanguages": [
    "ar",
    "fr",
    "es",
    "ja"
  ]
}

The translate command-line tool offers various options and commands to facilitate translation tasks. Below are the available options and commands along with examples of how to use them:

Options

  • -l, --localesPath <path-to>: Specifies the path for the locales directory. By default, it uses the path specified in the configuration file.

  • -c, --credentialsPath <path>: Specifies the path for the credentials file. By default, it uses the path specified in the configuration file.

  • -s, --sourceLanguage <code>: Specifies the source language code or source locale folder. By default, it uses the source language specified in the configuration file.

  • -t, --targetLanguages <codes...>: Specifies the target languages to translate into. Multiple target languages can be provided, separated by spaces. By default, it uses the target languages specified in the configuration file.

translate -l src/locales -s en -t fr es de

Commands

Add or Update Key

  • modify-key <namespace> <key> <value>: Adds or updates a key-value pair in the specified namespace and translates it.
translate modify-key common "greeting" "Hello, world!"

Translate

  • run-translations [languages...]: Translates modified keys(keys prefixed with ^ symbol) and updates all translation files for the specified languages. Languages are optional, if not provided it looks for all source files to translate.
translate run-translations
  • update-namespace <namespace>: Updates the entire translation file for the specified namespace and adds caret (^) to all keys. Example: translate update-namespace common

Note - For namespace just give the file name (do not add .json extension)

  • update-locales: Updates all source folder files and adds caret (^) to all untranslated keys. Example: translate update-locales

For more information on each command and option, use the --help flag with the command. For example: translate run-translations --help

Internationalization

For examples of using i18next with React and Next.js, refer to the following resources:

Contributing

Contributions are welcome! Please read the Contributing Guidelines for details on how to contribute to this project.

License

This project is licensed under the ISC License.