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

i18next-google-translate

v1.0.3

Published

Translate a folder of JSON files containing translations into multiple languages.

Downloads

81

Readme

i18next-google-translate

This tool allows you to automatically translate a locale folder containing multiple JSON files into multiple languages using Google Translate. You can either use the translation keys (natural translation) or their values (key-based translation) as a source for translations.

If some of the strings have already been translated, they won't be translated again. This improves performance and ensures that you won't accidentally lose existing translations.

ICU MessageFormat parts (e.g. {name}) aren't passed to Google Translate so their structure doesn't get mangled by the translation.

Prerequisites

To use this tool, you need to obtain valid credentials from Google. Follow these steps to get them:

  1. Select or create a Cloud Platform project
  2. Enable billing for your project (optional, I think)
  3. Enable the Google Cloud Translation API
  4. Set up authentication with a service account so you can access the API from your local workstation

You can specify the location of your downloaded JSON key file using the GOOGLE_APPLICATION_CREDENTIALS environment variable, either by setting it in your shell or by adding it to your .env file.

Installation

$ yarn add i18next-google-translate

Directory Structure

Your locales directory should look like this:

locales
├── de
├── en
│   ├── login.json
│   └── register.json
├── fr
└── it

If you don't specify another source language, this tool will translate all files located in the en into all other languages that exist as directories. A single language directory (e.g. en) should only contain JSON files. Sub-directories and other files will be ignored.

File Structure

There are two ways that i18next-google-translate can interpret files:

Natural Language

This is the default way that this tool will interpret your source files. The keys will be used as the basis of translations. If one or more of the values in your source files don't match their respective key, you'll see a warning as this could indicate an inconsistency in your translations. You can fix those inconsistencies by passing the --fix-inconsistencies flag.

{
  "Your username doesn't exist.": "Your username doesn't exist.",
  "{email} is not a valid email address.": "{email} is not a valid email address."
}

Key-Based

If you pass the --key-based flag, this tool will use the source file's values as the basis of translations.

{
  "ERROR_USERNAME": "Your username doesn't exist.",
  "ERROR_EMAIL": "{email} is not a valid email address."
}

Available Parameters

Options:
  -i, --input <inputDir>              The directory containing language directories (default: ".")
  -s, --source-language <sourceLang>  Specify the source language (default: "en")
  -k, --key-based                     Uses the template file's values instead of the keys as translation source
  -d, --delete-unused-strings         Deletes strings in translation files that don't exist in the template
  -h, --help                          output usage information

Contributing

If you'd like to contribute to this project, please feel free to open a pull request.