Provides log message translations.
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'
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'}}
Log message translation definitions
Attributes:
Parses the XML data into a class instance