V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
4357
V2EX  ›  Go 编程语言

一个 google translate 翻译工具

  •  
  •   4357 · 2017-06-23 09:07:07 +08:00 · 1401 次点击
    这是一个创建于 2470 天前的主题,其中的信息可能已经有所发展或是发生改变。

    https://github.com/fyh/interpretor

    实现:请求 google translate,翻译结果是一个 json 数组,拼接起来即可。

    示例:

    package main
    
    import (
        "fmt"
        "github.com/fyh/interpretor"
    )
    
    func main()  {
        i, _ := interpreter.Translate("hello, world", interpreter.ZH_CN)
        fmt.Println(i)
    
        i, _ = interpreter.Translate("你好,世界!", interpreter.EN)
        fmt.Println(i)
    }
    

    输出

    你好,世界
    Hello world!
    

    希望有用,轻喷。

    3 条回复    2017-06-23 10:08:48 +08:00
    unique
        1
    unique  
       2017-06-23 09:42:29 +08:00 via iPhone
    支持一下楼主
    4357
        2
    4357  
    OP
       2017-06-23 09:59:03 +08:00 via iPhone
    @unique 谢谢
    pathletboy
        3
    pathletboy  
       2017-06-23 10:08:48 +08:00
    默认的 http client 没有 timeout 的,运气不好就会卡死了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1408 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 23:46 · PVG 07:46 · LAX 16:46 · JFK 19:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.