V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
lcqtdwj
V2EX  ›  分享创造

够用,一个 Linux 下的翻译软件

  •  
  •   lcqtdwj ·
    jiffies · 2014-09-14 22:47:48 +08:00 · 7307 次点击
    这是一个创建于 3505 天前的主题,其中的信息可能已经有所发展或是发生改变。
    前段时间重装系统,发现Linux桌面多了好多有趣的软件。麒麟和深度带来很多新的东西。受openyoudao启发,写了一个翻译小软件,如其名,希望够用就好。

    现有的功能:
    1.在线查询,使用有道词典,直接用的有道的结果(因为界面真的清爽好看>0<)

    2.离线查询,使用开源的stardict词库,一开始自带了3个,需要其他词库也可以加,只要拷贝到dict文件夹就好。

    3.程序启动后在系统托盘处可以更换词典和切换使用在线离线查询,还有暂停查询。

    安装&运行:
    1.加入lz的ppa源:
    sudo add-apt-repository ppa:lcqtdwj/python-marisa-trie

    2.更新源:
    sudo apt-get update

    3.安装够用:
    sudo apt-get install gouyong

    如果提示依赖不满足,请执行
    sudo apt-get -f install
    安装依赖,然后再次安装。

    4.在启动器搜索够用,打开会在系统托盘出现够用图标。然后就可以划次翻译了,在线翻译可能会比较慢,请第一次多等一会。

    (注:条件原因,Lz只测试了ubuntu14.04,其他版本如果不能启动,请在终端输入:GouYong,把开始的几行复制给我,帮助够用改进,谢谢啦。)

    项目地址: https://github.com/jiffies/GouYong
    欢迎大家一起改进开发,让够用越来越够用,越来越舒服。
    13 条回复    2014-09-19 20:12:45 +08:00
    CRight
        1
    CRight  
       2014-09-14 22:59:36 +08:00 via Android
    支持!Linux上这类软件太少了。
    jacob
        2
    jacob  
       2014-09-14 23:25:10 +08:00 via iPhone
    好。谢楼主
    em70
        3
    em70  
       2014-09-15 01:01:47 +08:00
    linux厂商都在做系统本身,很少商业公司做开发工具,其实windows为啥统治桌面,不是系统本身多好,因为微软创业就是BASIC编译器起家的,最擅长为程序员服务,即使到今天VS仍然是最先进的IDE环境,社区也活跃.linux现状很难改变了,不过还有一个机会,那就是android,把这个分支发展为桌面,希望很大.
    polythene
        4
    polythene  
       2014-09-15 01:20:34 +08:00
    赞,加油!
    wenLiangcan
        5
    wenLiangcan  
       2014-09-15 10:49:15 +08:00
    试试
    wenLiangcan
        6
    wenLiangcan  
       2014-09-15 11:00:28 +08:00
    好吧,Arch 用户表示不知怎么解决依赖。。。。
    lcqtdwj
        7
    lcqtdwj  
    OP
       2014-09-15 13:24:08 +08:00
    @wenLiangcan 额,对Arch不熟悉,可以打成rpm包,但是有的依赖不知道Arch有没有。希望有Arch熟悉的小伙伴能够帮忙,打个方便的包。
    lcqtdwj
        8
    lcqtdwj  
    OP
       2014-09-15 13:24:21 +08:00
    @polythene 嘿嘿
    lcqtdwj
        9
    lcqtdwj  
    OP
       2014-09-15 13:24:43 +08:00
    @CRight 谢谢,欢迎试用
    wenLiangcan
        10
    wenLiangcan  
       2014-09-15 14:36:08 +08:00
    @lcqtdwj 就是那几个叫 gi 什么的依赖没有。。。
    Killian
        11
    Killian  
       2014-09-17 22:44:19 +08:00
    赞!确实需要一个简洁界面的 English Dictionary。为了学英语,我的观点是尽量用英文的解释来解释英文,所以我比较喜欢 Collins 词典。http://www.collinsdictionary.com/ 它有两个词典,一个English,一个English for learner (这里边的解释很易懂)。我现在在用python写一个抓取程序。我把大概的程序贴下,楼主觉得有用可以加到在线翻译的选项里。希望以后能在github上合作~


    # -*- coding: utf-8 -*-
    """
    Lookup word in Collins website
    version 0.1
    """
    import urllib, urllib2
    import re
    import codecs
    from BeautifulSoup import BeautifulSoup


    def selectDic():
    # which dictionary is used, 4 options
    datasets = ['american', 'american-cobuild-learners',
    'english', 'english-cobuild-learners']

    # For simplicity, 'american-cobuild-learners' for default
    # dic = 'american-cobuild-learners'
    dic = 'american'

    return dic

    def lookupWord():
    # Get the lookup word
    # Again, for illustration, we fixed the look-up word to 'geek'
    word = 'world'
    return word

    def getQuery(dic, word):
    query = {}
    query['dataset'] = dic
    query['q'] = word

    return query

    def parsePage(content, word):
    soup = BeautifulSoup(content)

    #Find the explanation part, id name is corresponding to the lookup word
    idname = word + "_1"
    rel = soup.findAll('div', id=idname)

    # unicode is for phonetic symbols
    rel = unicode.join(u'\n',map(unicode,rel))


    # There are icons for pronunciation request, for now, I deleted~~
    # Hope this can be added
    regx = r'(<img.*/>)';
    m = re.search(regx, rel)
    if m:
    rel = rel.replace(m.group(0), '')

    # For now, I save the result to a html to testify correctness
    # If it is a chrome extention, it can be shown immediately~~
    head = '<html><head><title>Page title</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body>'
    tail = '</body></html>'
    page = head + ''.join(rel) + tail

    return page

    def savePage(rel):
    f = codecs.open('dic.html','w','utf-8')
    f.write(rel)
    f.close()

    def queryPost():

    try:
    baseurl = "http://www.collinsdictionary.com/search";
    timeout = 10;

    dic = selectDic()
    word = lookupWord()

    query = getQuery(dic, word)

    data = urllib.urlencode(query);

    page = urllib2.urlopen(baseurl, data, timeout)
    content = page.read();

    rel = parsePage(content, word)
    savePage(rel)

    except:
    print "Error"


    if __name__ == "__main__":

    queryPost()
    print "Done"
    Killian
        12
    Killian  
       2014-09-17 22:54:15 +08:00
    啊,我忘了,有道是有Collins的 English for Learners 结果的 =.=
    没在linux环境下,也就没看楼主软件的结果,想当然了 whatever,祝GouYong get better and better
    lcqtdwj
        13
    lcqtdwj  
    OP
       2014-09-19 20:12:45 +08:00
    @Killian 谢谢>O<,最近在搞数学建模,暂时没时间看。。。有想法可以github加入。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1023 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 19:07 · PVG 03:07 · LAX 12:07 · JFK 15:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.