来源: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()
4 FEEDBACKS