lokalize 添加快捷键标签和转换中文标点

csslayer | 2011/11/26

来源:http://shuizhuyuanluo.blog.163.com/blog/static/7781812011102693427675/

两个很简单简单的 lokalize 的脚本,实际用下来 lokalize 的扩展性是相当强大的。

要正常使用得先安装 kdebindings 里面的 pykde4 和 kross python 解释器。把下面的文件复制到工程目录下的 lokalize-scripts 文件夹中就能用了。

不熟悉 python,功能也有缺陷的,比如快捷键标签只能无脑地插入在最后面,没有考虑点点点和专有名词;而转换标点的则没有转换引号,也没有考虑点点点。

就当是抛砖引玉吧。

add-acc.rc

<KrossScripting>
    <collection comment="Tools" name="tools" text="Tools">
        <script text="添加快捷键标签" name="add-acc" file="add-acc.py" interpreter="python" />
    </collection>
</KrossScripting>
add-acc.py
# -- coding: utf-8 --
import Editor

def addacc():     if not Editor.isValid():         return

    entry = Editor.currentEntry()     form = Editor.currentForm()     source = Editor.entrySource(entry, form)     target = Editor.entryTarget(entry, form)

    if not '&' in source:         return

    amp = source.find("&")     keyalnum = source[amp + 1]

    if not keyalnum.isalnum():         return

    target = target + '(&' + keyalnum.upper() + ')'     Editor.setEntryTarget(entry, form, target)

addacc()

conv-punc.rc
<KrossScripting>
    <collection comment="Tools" name="tools" text="Tools">
        <script text="转换标点符号" name="conv-punc" file="conv-punc.py" interpreter="python" />
    </collection>
</KrossScripting>
conv-punc.py
# -- coding: utf-8 --
import Editor

def convpunc():     if not Editor.isValid():         return

    entry = Editor.currentEntry()     form = Editor.currentForm()     target = Editor.entryTarget(entry, form)

    intab = u",.?!"     outtab = u",。?!"     table = dict((ord(a), b) for a, b in zip(intab, outtab))

    utarget = target.decode('utf-8')     Editor.setEntryTarget(entry, form, utarget.translate(table))

convpunc()

Tags:

4 FEEDBACKS

  1. 心之所在

    shuizhuyuanluo 水煮院落?

  2. dgy18787

    其实我是想问……有人用KDE出现plasmoid无法保存设置的情况吗,比如做了一些锁定图标的设置、以及调整plasmoid尺寸的设置

  3. @心之所在 同问,求nihui解释……

  4. @绿色圣光 @心之所在 拜托你们就不会想象成水竹院落吗……

Leave a Reply

Your email address will not be published. Required fields are marked *

Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).

This site uses Akismet to reduce spam. Learn how your comment data is processed.