How to use translate - 10 common examples

To help you get started, we’ve selected a few translate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Marak / say.js / examples / demo-translate.js View on Github external
/* 
  check out the translate.js project for more information
  http://github.com/marak/translate.js/

  requires installing the translate.js module via
  
  sudo npm install translate

*/

var say = require('../lib/say');
var translate = require('translate');

translate.text('Yo quero tacos por favor', function(result){
  say.speak('Alex', result);
});
github chrisl8 / ArloBot / node / node_modules / say / examples / demo-translate.js View on Github external
/* 
  check out the translate.js project for more information
  http://github.com/marak/translate.js/

  requires installing the translate.js module via
  
  sudo npm install translate

*/

var say = require('../lib/say');
var translate = require('translate');

translate.text('Yo quero tacos por favor', function(result){
  say.speak('Alex', result);
});
github ClementNerma / NightOS-v2 / apps / dolphin / dolphin.js View on Github external
// If the application was loaded as a launcher...
if(runtime.arguments.launcher) {
  debug.log('Running dolphin launcher...');

  // Run the launcher's file in the global's context
  system.loadScript(runtime.path + '/launcher.js', () => {
    debug.error(tr('Failed to load the launcher file'));
  });
} else {
  /** The translation package path
    * @type {string} */
  // NOTE: We load the translation only here because the launcher will have
  //       to load it by itself (translations are not synchronous between
  //       main and child processes)
  let tr_path = fs.makeAbsolute('translations/' + translate.language + '.ntp');

  // If the translation was not loaded and a package exists for this language...
  if(!translate.loaded(tr_path) && fs.fileExists(tr_path) === true) {
    // Load the translation package
    error = translate.load(translate.language, tr_path);
    // If an error occured
    if(e(error))
      // Make it fatal
      debug.error(`Failed to load the translation package for "${translate.language}"`, error);
  }

  /** The dolphin's explorer file
    * @type {string|NightError} */
  let content = fs.readFile('explorer.js');

  // If the reading failed...
github ClementNerma / NightOS-v2 / apps / dolphin / dolphin.js View on Github external
} else {
  /** The translation package path
    * @type {string} */
  // NOTE: We load the translation only here because the launcher will have
  //       to load it by itself (translations are not synchronous between
  //       main and child processes)
  let tr_path = fs.makeAbsolute('translations/' + translate.language + '.ntp');

  // If the translation was not loaded and a package exists for this language...
  if(!translate.loaded(tr_path) && fs.fileExists(tr_path) === true) {
    // Load the translation package
    error = translate.load(translate.language, tr_path);
    // If an error occured
    if(e(error))
      // Make it fatal
      debug.error(`Failed to load the translation package for "${translate.language}"`, error);
  }

  /** The dolphin's explorer file
    * @type {string|NightError} */
  let content = fs.readFile('explorer.js');

  // If the reading failed...
  if(e(content))
    // Make it fatal
    debug.error(tr('Failed to load the explorer script'), content);

  // Run the explorer file
  eval(content);
}
github ClementNerma / NightOS-v2 / apps / dolphin / dolphin.js View on Github external
// Run the launcher's file in the global's context
  system.loadScript(runtime.path + '/launcher.js', () => {
    debug.error(tr('Failed to load the launcher file'));
  });
} else {
  /** The translation package path
    * @type {string} */
  // NOTE: We load the translation only here because the launcher will have
  //       to load it by itself (translations are not synchronous between
  //       main and child processes)
  let tr_path = fs.makeAbsolute('translations/' + translate.language + '.ntp');

  // If the translation was not loaded and a package exists for this language...
  if(!translate.loaded(tr_path) && fs.fileExists(tr_path) === true) {
    // Load the translation package
    error = translate.load(translate.language, tr_path);
    // If an error occured
    if(e(error))
      // Make it fatal
      debug.error(`Failed to load the translation package for "${translate.language}"`, error);
  }

  /** The dolphin's explorer file
    * @type {string|NightError} */
  let content = fs.readFile('explorer.js');

  // If the reading failed...
  if(e(content))
    // Make it fatal
    debug.error(tr('Failed to load the explorer script'), content);

  // Run the explorer file
github ClementNerma / NightOS-v2 / apps / dolphin / dolphin.js View on Github external
debug.log('Running dolphin launcher...');

  // Run the launcher's file in the global's context
  system.loadScript(runtime.path + '/launcher.js', () => {
    debug.error(tr('Failed to load the launcher file'));
  });
} else {
  /** The translation package path
    * @type {string} */
  // NOTE: We load the translation only here because the launcher will have
  //       to load it by itself (translations are not synchronous between
  //       main and child processes)
  let tr_path = fs.makeAbsolute('translations/' + translate.language + '.ntp');

  // If the translation was not loaded and a package exists for this language...
  if(!translate.loaded(tr_path) && fs.fileExists(tr_path) === true) {
    // Load the translation package
    error = translate.load(translate.language, tr_path);
    // If an error occured
    if(e(error))
      // Make it fatal
      debug.error(`Failed to load the translation package for "${translate.language}"`, error);
  }

  /** The dolphin's explorer file
    * @type {string|NightError} */
  let content = fs.readFile('explorer.js');

  // If the reading failed...
  if(e(content))
    // Make it fatal
    debug.error(tr('Failed to load the explorer script'), content);
github ClementNerma / NightOS-v2 / apps / dolphin / dolphin.js View on Github external
/** The timer interface
  * @type {object} */
const timer = require('timer');

/** The system module
  * @type {object} */
const system = runtime.level >= fs.ROOT_LEVEL ? require('system') : null;

/** The web page's document
  * @type {Document} */
const document = system ? system.window.document : null;

/** The translation function
  * @type {function} */
const tr = translate.translate;

// If the application was loaded as a launcher...
if(runtime.arguments.launcher) {
  debug.log('Running dolphin launcher...');

  // Run the launcher's file in the global's context
  system.loadScript(runtime.path + '/launcher.js', () => {
    debug.error(tr('Failed to load the launcher file'));
  });
} else {
  /** The translation package path
    * @type {string} */
  // NOTE: We load the translation only here because the launcher will have
  //       to load it by itself (translations are not synchronous between
  //       main and child processes)
  let tr_path = fs.makeAbsolute('translations/' + translate.language + '.ntp');
github nodejitsu / kohai / lib / plugins / translate.js View on Github external
this.triggers.translate = function(name,to,message,languages,text) {
    //figure out who to respond to
    //if it was a private message to me, respond to the person
    //if it was to a room and not me specificall, reply in the room
    var destination = to === this.nick
      ? name
      : to
    
    var client = this
    if(text) {
      var pair = languages.split(/[:]/)

      translate.text({input:pair[0],output:pair[1]},text,function(txt) {
        //respond with the translated test, decoding the html entities
        client.say(destination,html.decode(txt))
      })
    }
    else {
      translate.text(languages,function(txt) {
        //respond with the translated test, decoding the html entities
        client.say(destination,html.decode(txt))
      })  
    }
  }
}
github nodejitsu / kohai / lib / plugins / translate.js View on Github external
//if it was to a room and not me specificall, reply in the room
    var destination = to === this.nick
      ? name
      : to
    
    var client = this
    if(text) {
      var pair = languages.split(/[:]/)

      translate.text({input:pair[0],output:pair[1]},text,function(txt) {
        //respond with the translated test, decoding the html entities
        client.say(destination,html.decode(txt))
      })
    }
    else {
      translate.text(languages,function(txt) {
        //respond with the translated test, decoding the html entities
        client.say(destination,html.decode(txt))
      })  
    }
  }
}
github chrisl8 / ArloBot / node / node_modules / say / node_modules / translate / examples / string.js View on Github external
var t = require('translate');
t.text("this is a test", function(err, txt) { 
  console.log(txt); 
});
  
t.text("this isn't a test", function(err, txt) { 
  console.log(txt); 
});

translate

Translate text to different languages on node.js and the browser

MIT
Latest version published 3 months ago

Package Health Score

69 / 100
Full package analysis