headless-google-translate

    1.3.0 • Public • Published

    headless-google-translate

    Call google translate service using headless browser.

    translator = require('headless-google-translate')
     
    my_tr = (str, cb) ->
      translator.tr 'en''zh-CN'strcb
     
    = console.log
     
    my_tr strp
    $ xvfb-run coffee hello_world.coffee
    你好,世界
    

    Since JSON is quite popular, you may happen to have your resource file in that format.

    translator = require('headless-google-translate')
     
    = console.log
     
    my_tr = (str, cb) ->
      translator.tr 'en''zh-CN'strcb
     
    obj =
      common: 'hello'
      header:
        title: 'support'
        body: 'about'
     
    tree_map = (f, tree) ->
      return if typeof tree isnt 'object'
      new_tree = {}
      for k,of tree
        new_tree[k=
          switch typeof v
            when 'string'
              f v
            when 'object'
              tree_map fv
      new_tree
     
    do ->
      acc = []
      = (x) -> acc.push x
      tree_map fobj
      my_tr acc.join('\n')(ret) ->
        acc = ret.split '\n'
        = (x) -> "#{x} ==> #{acc.shift()}"
        new_en = tree_map fobj
        p JSON.stringify(new_ennull2)
    $ xvfb-run coffee tree.coffee
    {
      "common": "hello ==> 你好",
      "header": {
        "title": "support ==> 支持",
        "body": "about ==> 关于"
      }
    }
    

    Install

    npm i headless-google-translate

    DownloadsWeekly Downloads

    1

    Version

    1.3.0

    License

    MIT

    Last publish

    Collaborators

    • albertnetymk