def serialize(text: TransText):
if isinstance(text, str):<EOL><INDENT>return {<EOL>'<STR_LIT:type>': '<STR_LIT:string>',<EOL>'<STR_LIT:value>': text,<EOL>}<EOL><DEDENT>elif isinstance(text, StringToTranslate):<EOL><INDENT>return {<EOL>'<STR_LIT:type>': '<STR_LIT>',<EOL>'<STR_LIT:key>': text.key,<EOL>'<STR_LIT:count>': text.count,<EOL>'<STR_LIT>': text.params,<EOL>}<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>.format(text.__class__.__name__))<EOL><DEDENT>
Takes as input either a string to translate either an actual string and
transforms it into a JSON-serializable structure that can be reconstructed
using `unserialize()`.