Table Of Contents

Previous topic

lexicontranslationtable.py

Next topic

db.py

This Page

messagetranslationtable.py

class MsgTransTableDef(XmlObject):

Provides log message translations.

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

Initializes the translation by processing the schema and xml documents for the message translation definitions.

>>> from simo.builder.translation.messagetranslationtable import MsgTransTableDef
>>> tdf = open('../../simulator/xml/schemas/Typedefs_SIMO.xsd')
>>> typedef = tdf.read()
>>> tdf.close()
>>> sf = open('../../simulator/xml/schemas/message_translation_table.xsd')
>>> schema = sf.read()
>>> sf.close()
>>> xml = u'''<message_translation_table
...      xmlns="http://www.simo-project.org/simo"
...      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...            <log_level name="test">
...               <logger name="simulation">
...                  <message>
...                     <from>Variable (.+)</from>
...                     <to>
...                        <lang name="fi">Muuttuja $1</lang>
...                        <lang name="se">Och det samma på svenska</lang>
...                     </to>
...                  </message>
...               </logger>
...               <logger name="optimization">
...                  <message>
...                     <from>something</from>
...                     <to>
...                        <lang name="fi">jotakin</lang>
...                        <lang name="se">någonting</lang>
...                        <lang name="de">etwas</lang>
...                     </to>
...                  </message>
...               </logger>
...            </log_level>
...         </message_translation_table>'''
>>> mtd = MsgTransTableDef(typedef)
>>> mtd.schema = schema
>>> mtd.xml = ('testxml', xml, None)
>>> mtd.xml['testxml'][:26]
u'<message_translation_table'

def xml_to_obj(self, root, lexicon):

Construct message translation table from the parsed translation table xml. The translation table is a dictionary keyed by log message level, which in turn is a dictionary keyed by the logger name. The items of this dictionary are two item tuples: (i) a list of tuples of regular expression pattern and corresponding original message string, (ii) a dictionary with original message strings as keys, and dictionaries with translated messages as data items and language identifiers as keys.

>>> mt = mtd.obj['testxml']
>>> mt.translation['test']['optimization'][0] 
[(<_sre.SRE_Pattern object at 0x...>, 'something')]
>>> mt.translation['test']['optimization'][1]
{'something': {'fi': u'jotakin', 'de': u'etwas', 'se': u'n\xc3\xa5gonting'}}

class MsgTransTable(object):

Log message translation definitions

Attributes:

  • translation: dictionary keyed by log message level, has
  • dictionary keyed by log message origin, has
  • a tuple of:
  • list of tuples of: regular expression patters (index 0) matching the original message (index)
  • dictionary keyed by the original message has
  • dictionary keyed by the language code has the translated message as data

def __init__(self, ns, elem):

Parses the XML data into a class instance