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

vtt-translate

v0.1.2

Published

Use Google Translate to translate VTT subtitle files.

Downloads

614

Readme

vtt-translate

Not exactly the best idea...

...but you can use this to Google Translate your .vtt subtitle files into other languages!

Requires Node.js 7.10.1 or later.

command line

install

npm install --global vtt-translate

use

$ vtt-translate 
Input VTT filename: ./vtt/transcript_en.vtt
Source language code: en
Destination language code: fr
Google Translate API key (https://cloud.google.com/translate/): [Paste your API key here]
Translating...
Translation complete!
Destination VTT filename: ./vtt/transcript_fr.vtt
$

See the Node API description for explanation of the command line inputs.

Note that API limits apply... if you fill your daily quota, a restore file will be saved so you can continue the next day without losing your progress:

$ vtt-translate 
Input VTT filename: ./vtt/transcript_en.vtt
Source language code: en
Destination language code: fr
Google Translate API key (https://cloud.google.com/translate/): [Paste your API key here]
Translating...
{ code: 403,
  message: 'User Rate Limit Exceeded',
  errors: 
   [ { message: 'User Rate Limit Exceeded',
       domain: 'usageLimits',
       reason: 'userRateLimitExceeded' } ],
  translatedCues: 
   [ ... ] }

Saving temp file so we can resume later where we left off...
$

Don't remove this temp file! Otherwise you'll have to start over from scratch later.

Once the download completes, the temp file will be deleted automatically.

Node API

install

npm install --save vtt-translate

use

This API example is functionally identical to the earlier command line example.

const { getTranslatedVttForPathname } = require('vtt-translate');
const fs = require('fs');

const pathname = './vtt/transcript_en.vtt';
const apiKey = '[Paste your API key here]';
const source = 'en';
const target = 'fr';

getTranslatedVttForPathname(pathname, apiKey, { source, target })
  .then(vttContent => {
    fs.writeFile('./vtt/transcript_fr.vtt', vttContent, err => {
      if (err) {
        console.error(err);
      }
    });
  })
  .catch(err => {
    console.error(err);
  });

API

getTranslatedVttForPathname(pathname, apiKey, params)

Arguments

  • pathname: The filesystem pathname for the source vtt file.
  • apiKey: A valid Google Cloud Translation API key
  • params.source: A language code supported by Google's Neural Machine Translation Model, corresponding to the language of the source text (e.g. 'en')
  • params.target A language code corresponding to the translation target language
  • params.restoredCuesPathname: A pathname pointing to a JSON file saved with a backup of previously translated cues (see error handling)

Returns

A Promise which resolves with the full text of the translated vtt file (as a string)

Error handling

If you .catch an error and the error has a translatedCues property, you can save that object to a json file and restore it later with params.restoredCuesPathname. This allows downloading a translation across multiple days if your API request quota is too small to download the translation in one day.