Translate configuration unknown words

This commit is contained in:
resteve 2015-02-13 08:28:39 +01:00
parent fc166dea56
commit 68a825a1fe
7 changed files with 50 additions and 2 deletions

View file

@ -2,11 +2,12 @@
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.pool import Pool
from .configuration import *
from .translate import *
def register():
Pool.register(
Configuration,
TranslateWizardStart,
TranslateWizardTranslation,
module='translate_apertium', type_='model')

14
configuration.py Normal file
View file

@ -0,0 +1,14 @@
#This file is part translate module for Tryton.
#The COPYRIGHT file at the top level of this repository contains
#the full copyright notices and license terms.
from trytond.model import fields
from trytond.pool import PoolMeta
__all__ = ['Configuration']
__metaclass__ = PoolMeta
class Configuration:
__name__ = 'translate.configuration'
apertium_unknown_words = fields.Boolean('Unknown Words',
help='Dissable Apertium unknown words')

12
configuration.xml Normal file
View file

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!-- This file is part translate_apertium module for Tryton.
The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="translate_configuration_view_form">
<field name="model">translate.configuration</field>
<field name="inherit" ref="translate.translate_configuration_view_form"/>
<field name="name">configuration_form</field>
</record>
</data>
</tryton>

View file

@ -13,6 +13,10 @@ class TranslateApertiumTestCase(unittest.TestCase):
def setUp(self):
trytond.tests.test_tryton.install_module('translate_apertium')
def test0005views(self):
'Test views'
test_view('translate')
def test0006depends(self):
'Test depends'
test_depends()

View file

@ -2,7 +2,7 @@
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
import subprocess
from trytond.pool import PoolMeta
from trytond.pool import Pool, PoolMeta
__all__ = ['TranslateWizardStart', 'TranslateWizardTranslation']
__metaclass__ = PoolMeta
@ -43,8 +43,13 @@ class TranslateWizardTranslation:
@classmethod
def get_translation_from_apertium(cls, text, source_lang, target_lang):
Config = Pool().get('translate.configuration')
trans_config = Config(1)
lang = '%s-%s' % (source_lang[:2], target_lang[:2])
cmd = ['apertium', lang]
if trans_config.apertium_unknown_words:
cmd.append('-u')
out, error = apertium_output(cmd, text)
if error:
cls.raise_user_error('error_translating', error_args=(text,))

View file

@ -4,3 +4,5 @@ depends:
ir
res
translate
xml:
configuration.xml

View file

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!-- This file is part translate_apertium module for Tryton.
The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/form" position="inside">
<separator id="apertium" string="Apertium" colspan="6"/>
<label name="apertium_unknown_words"/>
<field name="apertium_unknown_words"/>
</xpath>
</data>