def test_frontend_can_log_to_predefined_handler(self): custom_stream = StringIO() log = logging.getLogger('babel') log.addHandler(logging.StreamHandler(custom_stream)) self._run_init_catalog() self.assertNotEqual(id(sys.stderr), id(custom_stream)) self.assertEqual('', sys.stderr.getvalue()) assert len(custom_stream.getvalue()) > 0
def test_unknown_language_roundtrip(): buf = StringIO(r''' msgid "" msgstr "" "Language: sr_SP\n"''') catalog = pofile.read_po(buf) assert catalog.locale_identifier == 'sr_SP' assert not catalog.locale buf = BytesIO() pofile.write_po(buf, catalog) assert 'sr_SP' in buf.getvalue().decode()
continue # Get the translated test and insert it into the template translated_text = [] for prop in field: for text in prop['translatable_text']: translated_text.append(locale['locale'].ugettext(text)) translated_string = prop['template'] % tuple(translated_text) # Add the new translation to the catalog locale['catalog'].add(prop['raw_value'], translated_string) # Write every catalog with the new values for name, locale in locale_catalogs.iteritems(): # Again, if there is not catalog, simply go to the next one if 'catalog' not in locale: continue # Write the catalog to a string buf = StringIO() write_po(buf, locale['catalog']) # And the string to the file po_stream = open(locale['path'], 'w') po_stream.write(buf.getvalue()) po_stream.close() # If the file doesn't exist just do nothing except IOError as e: print(u'Template strings file does not exist, no action is necessary.')
translated_text = [] for prop in field: for text in prop['translatable_text']: translated_text.append( locale['locale'].ugettext(text)) translated_string = prop['template'] % tuple( translated_text) # Add the new translation to the catalog locale['catalog'].add(prop['raw_value'], translated_string) # Write every catalog with the new values for name, locale in locale_catalogs.iteritems(): # Again, if there is not catalog, simply go to the next one if 'catalog' not in locale: continue # Write the catalog to a string buf = StringIO() write_po(buf, locale['catalog']) # And the string to the file po_stream = open(locale['path'], 'w') po_stream.write(buf.getvalue()) po_stream.close() # If the file doesn't exist just do nothing except IOError as e: print(u'Template strings file does not exist, no action is necessary.')