
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
A fast command-line tool and TypeScript/JavaScript library for translating JSON files using Google Translate API. Features structure preservation, placeholder protection, batch translation, recursive search, incremental updates, array support, and program
A fast command-line tool and TypeScript/JavaScript library for translating JSON files and arrays using Google Translate API. Perfect for i18n (internationalization) workflows with batch translation, recursive search, incremental updates, array support, and programmatic API.
Test tr-file directly in your browser with our interactive demo! Upload JSON files or paste JSON content to see real-time translations.
npm install -g tr-file
npm install tr-file
tr_file <source-file> <target-languages> [options]
const { translateJSON } = require('tr-file');
const translations = await translateJSON({
"welcome": "Welcome to our app",
"nav.home": "Home"
}, ['es', 'fr', 'de']);
console.log(translations.es); // Spanish translations
Full TypeScript support with type definitions included:
import { translateJSON, TranslateAPI, TranslationResult } from 'tr-file';
// Type-safe translation
const result: TranslationResult = await translateJSON({
welcome: "Welcome to our app",
items: ["Home", "About", "Contact"]
}, ['es', 'fr']);
// Using the API class with types
const translator = new TranslateAPI({
sourceLanguage: 'en',
verbose: true
});
const strings: string[] = await translator.translateStrings(
["Hello", "World"],
'es'
);
π Full API Documentation β
# Translate en.json to Spanish, Japanese, and Portuguese (auto-detects source language)
tr_file en.json es,ja,pt
# Specify source language explicitly
tr_file myfile.json es,ja,pt --source-lang en
# With custom API key
tr_file en.json es,ja,pt -k YOUR_API_KEY
# With custom delay between requests
tr_file en.json es,ja,pt -d 200
# Recursive translation - find all 'en.json' files in subdirectories
tr_file en.json es,fr,de --recursive
# Recursive with explicit source language
tr_file content.json es,fr,de -r -s en
By default, tr-file
automatically detects the source language of your content. However, you can specify it explicitly:
# Auto-detect source language (default)
tr_file content.json es,fr,de
# Specify source language explicitly
tr_file content.json es,fr,de --source-lang en
tr_file content.json es,fr,de -s fr # Short form
Benefits of specifying source language:
Automatically protects content in curly braces {placeholder}
from translation:
# Input: {"message": "Hello {username}, you have {count} notifications"}
# Output: {"message": "Hola {username}, tienes {count} notificaciones"}
tr_file messages.json es
Example:
{
"greeting": "Welcome {name}!",
"status": "You have {count} messages",
"complex": "Processing {items.processed} of {items.total} items"
}
Translates to (Spanish):
{
"greeting": "Β‘Bienvenido {name}!",
"status": "Tienes {count} mensajes",
"complex": "Procesando {items.processed} de {items.total} elementos"
}
Maintains your exact JSON structure:
{
"flat.key": "Flat key with dots",
"nested": {
"key": "Nested key"
},
"array": ["Item 1", "Item 2"],
"mixed": {
"text": "Translate this",
"number": 42,
"boolean": true
}
}
Features:
"test.test"
remain as flat keysSearch for and translate all files with a specific name in all subdirectories:
# Find all 'en.json' files recursively and translate them
tr_file en.json es,fr,de --recursive
# Short form with -r flag
tr_file en.json es,fr,de -r
# Recursive with explicit source language
tr_file content.json es,fr,de -r -s en
Recursive Example:
project/
βββ frontend/
β βββ locales/
β βββ en.json β Found and translated
β βββ es.json β Generated
β βββ fr.json β Generated
βββ backend/
β βββ i18n/
β βββ en.json β Found and translated
β βββ es.json β Generated
β βββ fr.json β Generated
βββ mobile/
βββ lang/
βββ en.json β Found and translated
βββ es.json β Generated
βββ fr.json β Generated
-k, --key <key>
: Google Translate API key (optional - uses built-in key if not provided)-s, --source-lang <lang>
: Source language code (e.g., en, es, fr) - auto-detected if not provided-d, --delay <ms>
: Delay between requests in milliseconds (default: 50ms)-r, --recursive
: Search for source file in all subdirectoriesQuick Start: The tool works immediately with a built-in API key - no setup required!
# Install and use right away
npm install -g tr-file
tr_file en.json es,ja,pt
Optional - Use your own API key:
Get a Google Translate API key:
Set your API key (choose one method):
# Option 1: Environment variable
export GOOGLE_TRANSLATE_API_KEY="your-api-key-here"
# Option 2: Use the -k flag
tr_file en.json es,ja,pt -k "your-api-key-here"
"test.test"
as flat keys, nested objects as nested{username}
from translationInput (en.json):
{
"greeting": "Hello",
"navigation": {
"home": "Home",
"about": "About Us"
},
"messages": {
"welcome": "Welcome to our app",
"goodbye": "Thank you for visiting"
}
}
Output (es.json):
{
"greeting": "Hola",
"navigation": {
"home": "Inicio",
"about": "Acerca de nosotros"
},
"messages": {
"welcome": "Bienvenido a nuestra aplicaciΓ³n",
"goodbye": "Gracias por visitarnos"
}
}
The tool supports all languages supported by Google Translate API. Common language codes include:
es
- Spanishfr
- Frenchde
- Germanit
- Italianpt
- Portugueseja
- Japaneseko
- Koreanzh
- Chineseru
- Russianar
- ArabicThe tool intelligently handles existing translation files:
Example:
# First run - translates all keys
tr_file en.json es # Creates es.json with all translations
# Add new keys to en.json
echo '{"new.key": "New text"}' >> en.json
# Second run - only translates new keys
tr_file en.json es # Only translates "new.key", preserves existing translations
The tool uses batch translation for maximum efficiency:
Example Performance:
The tool includes built-in rate limiting to avoid hitting Google Translate API limits. You can adjust the delay between requests using the -d
option.
MIT
[1.4.6] - 2025-07-21
FAQs
A fast command-line tool and TypeScript/JavaScript library for translating JSON files using Google Translate API. Features structure preservation, placeholder protection, batch translation, recursive search, incremental updates, array support, and program
The npm package tr-file receives a total of 5 weekly downloads. As such, tr-file popularity was classified as not popular.
We found that tr-file demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socketβs new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.