Table Of Contents

Previous topic

simcontrol.py

Next topic

messagetranslationtable.py

This Page

lexicontranslationtable.py

class LexiconTransTableDef(XmlObject):

Provides lexicon data level and variable name translations for log messages.

def __init__(self, typedef, schema, xmldata):

Initializes the translation by processing the schema and xml documents for the lexicon translation definitions:

>>> from simo.builder.translation.lexicontranslationtable import LexiconTransTableDef
>>> tdf = open('../../simulator/xml/schemas/Typedefs_SIMO.xsd')
>>> typedef = tdf.read()
>>> tdf.close()
>>> sf = open('../../simulator/xml/schemas/lexicon_translation_table.xsd')
>>> schema = sf.read()
>>> sf.close()
>>> xml = u'''<lexicon_translation_table
...           xmlns="http://www.simo-project.org/simo"
...           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...            <level>
...               <name>
...                  <from>comp_unit</from>
...                  <to>
...                     <lang name="fi">kuvio</lang>
...                     <lang name="se">nånting</lang>
...                  </to>
...               </name>
...               <variables>
...                  <variable>
...                     <name>
...                         <from>DEVEL_CLASS</from>
...                         <to>
...                            <lang name="fi">kehitysluokka</lang>
...                         </to>
...                     </name>
...                     <values>
...                        <value>
...                            <from>Open regeneration site</from>
...                            <to>
...                               <lang name="fi">aukea</lang>
...                            </to>
...                        </value>
...                        <value>
...                           <from>Young seedling stand (less than 1,3 m)</from>
...                          <to>
...                              <lang name="fi">pieni taimikko</lang>
...                          </to>
...                        </value>
...                     </values>
...                  </variable>
...                  <variable>
...                     <name>
...                        <from>INVENTORY_METHOD</from>
...                        <to>
...                           <lang name="fi">inventointitapa</lang>
...                           <lang name="se">så ska det vara</lang>
...                        </to>
...                     </name>
...                     <values>
...                        <value>
...                           <from>some method</from>
...                           <to>
...                              <lang name="fi">joku inventointi</lang>
...                              <lang name="se">ju inventering ja</lang>
...                           </to>
...                        </value>
...                     </values>
...                  </variable>
...               </variables>
...            </level>
...         </lexicon_translation_table>'''
>>> ltd = LexiconTransTableDef(typedef)
>>> ltd.schema = schema
>>> ltd.xml = ('testxml',xml, None)
>>> ltd.xml['testxml'][:26]
u'<lexicon_translation_table'

def xml_to_obj(self, root, lexicon):

Construct lexicon data level name and variable name translation tables from the parsed translation table xml.

Only one translation table, keyed as ‘default’ is supported.

The lexicon data level name table is a dictionary (by data level name in single quotes) of language codes yielding unicode translation strings:

>>> lt = ltd.obj['testxml']
>>> lt.level_table["'comp_unit'"]['fi']
u"'kuvio'"

The data level variable table is similar dictionary yielding unicode translation strings:

>>> lt.var_table["'DEVEL_CLASS'"]['fi']
u"'kehitysluokka'"

class LexiconTransTable(object):

Lexicon translation definitions.

Attributes:

  • level_table: dictionary, level name as key, dictionary of language code: level name translation as data
  • var_table: dictionary, variable as key, dictionary of language code: variable name translation as data

def __init__(self, ns, elem):

Parses the XML data into a class instance