# project-translator

> A project translator

Latest version **2.0.2** (published 2024-01-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install project-translator
pnpm add project-translator
yarn add project-translator
bun add project-translator
```

Provides the command `project-translator`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2024-01-31 |
| First published | 2019-07-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 3.5 MB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Doug Kiser |
| Maintainers | douglasskiser |

## Links

- npm: https://www.npmjs.com/package/project-translator
- Repository: https://github.com/douglasskiser/project-translator
- Homepage: https://github.com/douglasskiser/project-translator#readme
- Issues: https://github.com/douglasskiser/project-translator/issues
- npm.io page: https://npm.io/package/project-translator

## Dependencies (8)

- [eslint](https://npm.io/package/eslint.md) ^8.48.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [esbuild](https://npm.io/package/esbuild.md) ^0.19.3
- [inquirer](https://npm.io/package/inquirer.md) ^9.2.11
- [commander](https://npm.io/package/commander.md) ^11.0.0
- [@google-cloud/translate](https://npm.io/package/@google-cloud/translate.md) ^8.0.2
- [@aws-sdk/client-translate](https://npm.io/package/@aws-sdk/client-translate.md) ^3.418.0
- [@formatjs/icu-messageformat-parser](https://npm.io/package/@formatjs/icu-messageformat-parser.md) ^2.7.6

## Recent versions

- 2.0.2 (latest) — 2024-01-31
- 2.0.1 — 2023-10-01
- 2.0.0 — 2023-09-30
- 1.0.4 — 2021-02-14
- 1.0.3 — 2020-05-01
- 1.0.2 — 2019-11-03
- 1.0.1 — 2019-09-11
- 1.0.0 — 2019-07-10

## README

[![NPM Version](https://img.shields.io/npm/v/project-translator)](https://www.npmjs.com/package/project-translator)

# project-translator
A translator for web applications that uses AWS, GCP, or any custom provider.

## Install
```sh
npx project-translator
```
```sh
npm i --save-dev project-translator
```

### Setup
To configure your project to use the project-translator you only need `.translaterc.json` file in the root of your project. You can run `project-translator init` to auto generate this file.

Example .translaterc.json
```javascript
{
  "provider": "aws", // aws | google | custom
  "translationDir": "lib/translations",
  "sourceLanguage": "en-US",
  "outputLanguages": [
    "fr-FR", "es-ES"
  ],
  "region": "us-east-1", // when using AWS
  "projectId": "my-project1", // when using Google
  "useIcuLabels": true // when using ICU labels
}
 ```

### Google Setup
To use Google as your translate provider you will need to export your application credentials so that you can authenticate with Google's service.

```sh
export GOOGLE_APPLICATION_CREDENTIALS="./path-to/credentials.json"
```

### AWS Setup
To use AWS as your translate provider, follow the aws-cli setup found here https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html
   
  
### File/File-Name Structure
Translation files shoud be in JSON format and use naming convention that beings with a two letter language code  (e.g 'en.json' or 'en-US.json'). While translating the translations directory provided in the configuration file as `translationsDir` will be used to find, create or update translation files.

Example Source Translation File
```javascript
// en-US.json
{
  "my-label": "My Label",
  "section-label": "Label for a section",
  "section-header": {
    "title": "A Title",
    "description": "A description"
  },
  "another.section.header": "Title"
}
 ```

 ### Use Translator
`npx project-translator translate`


 To start translating, ensure you have a source language file in your translations directory. This source file's language code should be configured in your `.translaterc.json` file. Now run `npx project-translator translate` or install and use in your package.json scripts.

 Example package.json
 ```json
 {
  "scripts": {
    "translate": "project-translator translate"
  }
 }
 ```

 ### Custom Translate Provider

 To use a customer provider you can provide these values in your `.translaterc.json` file.

 ```json
 {
  "provider": "custom",
  "translatorPath": "./path-to/custom-translator.js"
 }
 ```

 Example Custom Translator
 ```javascript
 export default function customTranslator() {
  return {
    translate:
      (sourceLanguage:string, targetLanguage:string) => async function(text:string) {
        // put you custom translate code here.
        const translatedText = await customProvider(text, sourceLanguage, targetLanguage);
        // Ensure it returns the translated text.
        return translatedText;
      }
  };
 }
 ```

---
_Source: https://npm.io/package/project-translator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
