Exemple #1
0
    def setUp(self):
        # Add a new entry for testing purposes. It's a template one.
        self.translation_import_queue = getUtility(ITranslationImportQueue)
        template_path = 'po/testing.pot'
        by_maintainer = True
        personset = getUtility(IPersonSet)
        importer = personset.getByName('carlos')
        productset = getUtility(IProductSet)
        firefox = productset.getByName('firefox')
        firefox_trunk = firefox.getSeries('trunk')
        template_entry = self.translation_import_queue.addOrUpdateEntry(
            template_path, test_kde_template, by_maintainer, importer,
            productseries=firefox_trunk)

        # Add another one, a translation file.
        pofile_path = 'po/sr.po'
        translation_entry = self.translation_import_queue.addOrUpdateEntry(
            pofile_path, test_kde_translation_file, by_maintainer, importer,
            productseries=firefox_trunk)

        # Add a non-KDE PO file which gets recognized as regular PO file
        # (we use different productseries so it doesn't conflict with
        # KDE PO file being imported into firefox_trunk)
        firefox_10 = firefox.getSeries('1.0')
        gettext_template_entry = (
            self.translation_import_queue.addOrUpdateEntry(
                template_path, test_template, by_maintainer, importer,
                productseries=firefox_10))

        transaction.commit()
        self.template_importer = KdePOImporter()
        self.template_file = self.template_importer.parse(template_entry)
        self.translation_importer = KdePOImporter()
        self.translation_file = self.translation_importer.parse(
            translation_entry)

        self.gettext_template_entry = gettext_template_entry
Exemple #2
0
)
from lp.translations.interfaces.translations import TranslationConstants
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