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

tarjm

v1.0.6

Published

tarjmate text from one language to another

Downloads

2

Readme

Tarjm

Tarjm is a command-line tool and Node.js module for translating text from one language to another using a translation server. It allows you to translate text directly from the command line or integrate translation functionality into your Node.js applications.

Table of Contents

Features

  • Translate text between multiple languages.
  • Set a default target language.
  • Read text to translate from a file.
  • Use as a CLI tool or integrate into Node.js scripts.
  • Customizable via a configuration file.

Installation

Globally (For CLI Usage)

npm install -g tarjm

Locally (For Module Usage)

In your project directory:

npm install tarjm

Usage

Command-Line Interface (CLI)

After installing globally, you can use tarjm directly in your terminal.

Syntax

tarjm [options] [text_to_translate]

Options

  • -d, --default <language>
    Set the default target language for translation. This setting is saved in the config file (~/.config/tarjm/config.json). If no text or file is provided, the script will exit after setting the default language.

  • -l, --language <language>
    Specify the target language for this translation. This option overrides the default language set in the config.

  • -f, --file <path>
    Read the text to translate from the specified file.

  • -h, --help
    Display the help message.

Examples

  • Translate Text to Default Language

    tarjm "Hello World"

    Translates "Hello World" to the default language (or English if not set).

  • Translate Text to Specified Language

    tarjm -l es "Hello World"

    Translates "Hello World" to Spanish.

  • Set Default Language

    tarjm -d fr

    Sets the default language to French.

  • Translate Text from a File

    tarjm -f mytext.txt

    Translates the content of mytext.txt to the default language.

  • Display Help Message

    tarjm -h

    Displays the help message.

Output

The translated text will be displayed in the terminal:

Translated Text:

Hola Mundo

Node.js Module

You can also use tarjm within your Node.js applications by importing it as a module.

Importing

import { tarjm } from 'tarjm';

Syntax

tarjm(args = process.argv.slice(2))
  • args: An array of arguments similar to command-line arguments.

Examples

  • Basic Translation

    import { tarjm } from 'tarjm';
    
    async function translateText() {
      try {
        const translatedText = await tarjm(['Hello World']);
        console.log('Translated Text:', translatedText);
      } catch (error) {
        console.error('Error during translation:', error.message);
      }
    }
    
    translateText();
  • Translate to Specified Language

    import { tarjm } from 'tarjm';
    
    async function translateToSpanish() {
      try {
        const translatedText = await tarjm(['-l', 'es', 'Good morning']);
        console.log('Translated Text:', translatedText);
      } catch (error) {
        console.error('Error:', error.message);
      }
    }
    
    translateToSpanish();
  • Set Default Language in Script

    import { tarjm } from 'tarjm';
    
    async function setDefaultLanguage() {
      try {
        await tarjm(['-d', 'de']);
        console.log('Default language set to German.');
      } catch (error) {
        console.error('Error:', error.message);
      }
    }
    
    setDefaultLanguage();
  • Translate Text from a File

    import { tarjm } from 'tarjm';
    
    async function translateFromFile() {
      try {
        const translatedText = await tarjm(['-f', 'mytext.txt']);
        console.log('Translated Text:', translatedText);
      } catch (error) {
        console.error('Error:', error.message);
      }
    }
    
    translateFromFile();

Handling Errors

When using as a module, ensure to handle errors appropriately using try...catch blocks, as shown in the examples.

Configuration

The configuration file is located at ~/.config/tarjm/config.json. It stores the default target language.

Setting the Default Language

  • Via CLI

    tarjm -d <language_code>

    Example:

    tarjm -d es
  • Programmatically

    import { tarjm } from 'tarjm';
    
    async function setDefaultLanguage() {
      await tarjm(['-d', 'es']);
    }
    
    setDefaultLanguage();

Config File Structure

{
  "defaultLanguage": "es"
}

Dependencies

Ensure your environment has access to a translation server at http://tarjm:5000/translate.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

Development Setup

  1. Clone the Repository

    git clone https://github.com/yourusername/tarjm.git
  2. Install Dependencies

    npm install
  3. Link the Package Locally

    npm link
  4. Test the CLI

    tarjm -h
  5. Run Tests

    (Add your testing commands here)

License

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