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

@kabeep/node-translate-i18n

v1.1.0

Published

A command-line interface tool for translating localization files to other languages.

Downloads

4

Readme

A command-line interface tool for translating localization files to other languages.


NodeJS License NPM Codecov Codacy CircleCI

English | 简体中文

Alt

📖 Introduction

Node Translate I18n is a tool for multilingual internationalization, enabling easy translation of localization files into other languages. Translate a Chinese localization file zh-CN.js, for example, into an English localization file en-US.js.

With a simple command-line interface, you can quickly convert your project's localization files into the desired target language, facilitating cross-language i18n support in NodeJS project.

⚙️ Installation

npm install @kabeep/node-translate-i18n --save
yarn add @kabeep/node-translate-i18n
pnpm add @kabeep/node-translate-i18n

🚀 Usage

Using in javascript

import localize from '@kabeep/node-translate-i18n';

localize({
    _: ['./src/locale/en-US.ts'],
    to: ['zh-CN', 'ja-JP'],
    rewrite: true,
})
    .then(console.log)
    .catch(console.error);

Using in terminal

localize ./en-US.ts -t "zh-CN" "ja-JP" -r
Usage: localize <path> [options]

Options:
  -t, --to       Target language, specified as ISO 639-1 code [array] [required]
  -r, --rewrite  Overwrite the file or phrase if it exists
                                                      [boolean] [default: false]
  -v, --version  Show version number                                   [boolean]
  -h, --help     Show help                                             [boolean]

Examples:
  localize ./en-US.ts -t zh-CN -r  Overwrite an existing file or phrase
  localize ./en-US.js -t zh-CN     Use javascript locale files
  localize ./en-US.ts -t zh-CN     Use typescript locale files
  localize ./en-US.json -t zh-CN   Use json locale file

🪄 Examples

Append

For localized files that do not exist, the cli will create and write a new file using the translation from the source file. (The file name comes from the to parameter).

# locale
#   ├── en-US.js (1 row)
# =>
# locale
#   ├── en-US.js (1 row)
# + ├── zh-CN.js (1 row)
localize ./locale/en-US.js -t "zh-CN"

Diff

When the localization file in the to parameter already exists, only the new phrases will be written via diff. This is useful when certain phrases have been manually modified with more accurate translation results.

# locale
#   ├── en-US.js (2 row)
#   ├── zh-CN.js (1 row)
#   ├── ja-JP.js (2 row)
# =>
# locale
#   ├── en-US.js (2 row)
# M ├── zh-CN.js (2 row)
#   ├── ja-JP.js (2 row)
localize ./locale/en-US.js -t "zh-CN" "ja-JP"

Rewrite

When the localization file in the to parameter already exists, the existing phrase will be overwritten.

# locale
#   ├── en-US.js (2 row)
#   ├── zh-CN.js (2 row)
#   ├── ja-JP.js (2 row)
# =>
# locale
#   ├── en-US.js (2 row)
# M ├── zh-CN.js (2 row)
# M ├── ja-JP.js (2 row)
localize ./locale/en-US.js -t "zh-CN" "ja-JP" -r

🔩 Supported to parameters

en, zh, ru, ...
en-US, zh-CN, zh-TW, ru-RU, ...
  • Custom file suffix
en-US.locale, zh-CN.locale, zh-TW.locale, ru-RU.locale, ...

📄 Supported file extensions

  • Javascript
  • Typescript
  • JSON

</> Supported code styles

Unlimited key-value pairs can be viewed format.js docs or polyglot.js docs

Here is an example:

{
    "GREETING": "Hello {{name}}"
}

or

export default {
    "GREETING": "Hello {{name}}"
}

🔗 Related

  • i18n-cli - A CLI tool that utilizes the OpenAI API to translate JSON-based locale files
  • locize-cli - locize cli to import / export locales, add / edit / remove, sync segments
  • node-polyglot - Give your JavaScript the ability to speak many languages.
  • node-translate - 🦜 A powerful, secure and feature-rich api via Google Translation.
  • node-translate-cli - > A powerful, secure and feature-rich tool via Google Translation in terminal. _

🤝 Contribution

Contributions via Pull Requests or Issues are welcome.

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.