def test_Contexts(self): """Test that message context in XPI file is set to chrome path.""" queue_entry = self.setUpTranslationImportQueueForTranslation( 'clashing_ids') importer = MozillaXpiImporter() template = importer.parse(queue_entry) messages = sorted([(message.msgid_singular, message.context, message.singular_text) for message in template.messages]) self.assertEquals([ (u'foozilla.clashing.key', u'mac/extra.dtd', u'This message is Mac-specific, and comes from DTD.'), (u'foozilla.clashing.key', u'mac/extra.properties', u'This message is Mac-specific, and comes from properties.'), (u'foozilla.clashing.key', u'main/main.dtd', u'This message is in the main DTD.'), (u'foozilla.clashing.key', u'main/main.properties', u'This message is in the main properties file.'), (u'foozilla.clashing.key', u'unix/extra.dtd', u'This message is Unix-specific, and comes from DTD.'), (u'foozilla.clashing.key', u'unix/extra.properties', u'This message is Unix-specific, and comes from properties.'), (u'foozilla.clashing.key', u'win/extra.dtd', u'This message is Windows-specific, and comes from DTD.'), (u'foozilla.clashing.key', u'win/extra.properties', u'This message is Windows-specific, ' 'and comes from properties.'), (u'foozilla.regular.message', u'main/main.dtd', u'A non-clashing message.'), ], messages)
def test_GetLastTranslator(self): """Tests whether we extract last translator information correctly.""" translation_entry = self.setUpTranslationImportQueueForTranslation( 'en-US') importer = MozillaXpiImporter() translation_file = importer.parse(translation_entry) # Let's try with the translation file, it has valid Last Translator # information. name, email = translation_file.header.getLastTranslator() self.assertEqual(name, u'Carlos Perell\xf3 Mar\xedn') self.assertEqual(email, u'*****@*****.**')
class MozillaXpiImporterTestCase(unittest.TestCase): """Class test for mozilla's .xpi file imports""" layer = LaunchpadZopelessLayer def setUp(self): self.importer = MozillaXpiImporter() def testInterface(self): """Check whether the object follows the interface.""" self.failUnless( verifyObject(ITranslationFormatImporter, self.importer)) def testFormat(self): """Check that MozillaXpiImporter handles the XPI file format.""" format = self.importer.getFormat(u'') self.failUnless( format == TranslationFileFormat.XPI, 'MozillaXpiImporter format expected XPI but got %s' % format.name) def testHasAlternativeMsgID(self): """Check that MozillaXpiImporter has an alternative msgid.""" self.failUnless( self.importer.uses_source_string_msgids, "MozillaXpiImporter format says it's not using alternative msgid" " when it really does!")
class MozillaXpiImporterTestCase(unittest.TestCase): """Class test for mozilla's .xpi file imports""" layer = LaunchpadZopelessLayer def setUp(self): self.importer = MozillaXpiImporter() def testInterface(self): """Check whether the object follows the interface.""" self.failUnless(verifyObject(ITranslationFormatImporter, self.importer)) def testFormat(self): """Check that MozillaXpiImporter handles the XPI file format.""" format = self.importer.getFormat(u'') self.failUnless( format == TranslationFileFormat.XPI, 'MozillaXpiImporter format expected XPI but got %s' % format.name) def testHasAlternativeMsgID(self): """Check that MozillaXpiImporter has an alternative msgid.""" self.failUnless( self.importer.uses_source_string_msgids, "MozillaXpiImporter format says it's not using alternative msgid" " when it really does!")
def test_Contexts(self): """Test that message context in XPI file is set to chrome path.""" queue_entry = self.setUpTranslationImportQueueForTranslation( 'clashing_ids') importer = MozillaXpiImporter() template = importer.parse(queue_entry) messages = sorted([ (message.msgid_singular, message.context, message.singular_text) for message in template.messages]) self.assertEquals( [ (u'foozilla.clashing.key', u'mac/extra.dtd', u'This message is Mac-specific, and comes from DTD.'), (u'foozilla.clashing.key', u'mac/extra.properties', u'This message is Mac-specific, and comes from properties.'), (u'foozilla.clashing.key', u'main/main.dtd', u'This message is in the main DTD.'), (u'foozilla.clashing.key', u'main/main.properties', u'This message is in the main properties file.'), (u'foozilla.clashing.key', u'unix/extra.dtd', u'This message is Unix-specific, and comes from DTD.'), (u'foozilla.clashing.key', u'unix/extra.properties', u'This message is Unix-specific, and comes from properties.'), (u'foozilla.clashing.key', u'win/extra.dtd', u'This message is Windows-specific, and comes from DTD.'), (u'foozilla.clashing.key', u'win/extra.properties', u'This message is Windows-specific, ' 'and comes from properties.'), (u'foozilla.regular.message', u'main/main.dtd', u'A non-clashing message.'), ], messages)
def setUp(self): self.importer = MozillaXpiImporter()
from lp.translations.utilities.gettext_po_importer import GettextPOImporter from lp.translations.utilities.kde_po_importer import KdePOImporter from lp.translations.utilities.mozilla_xpi_importer import MozillaXpiImporter from lp.translations.utilities.sanitize import ( sanitize_translations_from_import, ) from lp.translations.utilities.translation_common_format import ( TranslationMessageData, ) from lp.translations.utilities.validate import ( GettextValidationError, validate_translation, ) importers = { TranslationFileFormat.KDEPO: KdePOImporter(), TranslationFileFormat.PO: GettextPOImporter(), TranslationFileFormat.XPI: MozillaXpiImporter(), } def is_identical_translation(existing_msg, new_msg): """Is a new translation substantially the same as the existing one? Compares msgid and msgid_plural, and all translations. :param existing_msg: a `TranslationMessageData` representing a translation message currently kept in the database. :param new_msg: an alternative `TranslationMessageData` translating the same original message. :return: True if the new message is effectively identical to the existing one, or False if replacing existing_msg with new_msg would make a semantic difference.