Example #1
0
    def __init__(self, vcs_project, path):
        """
        Load the resource file for each enabled locale and store its
        translations in VCSEntity instances.
        """
        from pontoon.base import formats  # Avoid circular import.

        self.vcs_project = vcs_project
        self.path = path
        self.files = {}
        self.entities = {}

        # Create entities using resources from the source directory,
        source_resource_path = os.path.join(
            vcs_project.source_directory_path(), self.path)

        # Special case: Source files for pofiles are actually .pot.
        if source_resource_path.endswith('po'):
            source_resource_path += 't'

        source_resource_file = formats.parse(source_resource_path)
        for index, translation in enumerate(source_resource_file.translations):
            vcs_entity = VCSEntity(
                resource=self,
                key=translation.key,
                string=translation.source_string,
                string_plural=translation.source_string_plural,
                comments=translation.comments,
                source=translation.source,
                order=translation.order or index)
            self.entities[vcs_entity.key] = vcs_entity

        # Fill in translations from the locale resources.
        for locale in vcs_project.db_project.locales.all():
            resource_path = os.path.join(
                vcs_project.locale_directory_path(locale.code), self.path)
            try:
                resource_file = formats.parse(resource_path,
                                              source_resource_path)
            except IOError:
                continue  # File doesn't exist, let's move on

            self.files[locale] = resource_file
            for translation in resource_file.translations:
                try:
                    self.entities[translation.key].translations[
                        locale.code] = translation
                except KeyError:
                    # If the source is missing an entity, we consider it
                    # deleted and don't add it.
                    pass
Example #2
0
    def __init__(self, vcs_project, path):
        """
        Load the resource file for each enabled locale and store its
        translations in VCSEntity instances.
        """
        from pontoon.base import formats  # Avoid circular import.

        self.vcs_project = vcs_project
        self.path = path
        self.files = {}
        self.entities = {}

        # Create entities using resources from the source directory,
        source_resource_path = os.path.join(vcs_project.source_directory_path(), self.path)

        # Special case: Source files for pofiles are actually .pot.
        if source_resource_path.endswith('po'):
            source_resource_path += 't'

        source_resource_file = formats.parse(source_resource_path)
        for index, translation in enumerate(source_resource_file.translations):
            vcs_entity = VCSEntity(
                resource=self,
                key=translation.key,
                string=translation.source_string,
                string_plural=translation.source_string_plural,
                comments=translation.comments,
                source=translation.source,
                order=translation.order or index
            )
            self.entities[vcs_entity.key] = vcs_entity

        # Fill in translations from the locale resources.
        for locale in vcs_project.db_project.locales.all():
            resource_path = os.path.join(
                vcs_project.locale_directory_path(locale.code),
                self.path
            )
            try:
                resource_file = formats.parse(resource_path, source_resource_path)
            except IOError:
                continue  # File doesn't exist, let's move on

            self.files[locale] = resource_file
            for translation in resource_file.translations:
                try:
                    self.entities[translation.key].translations[locale.code] = translation
                except KeyError:
                    # If the source is missing an entity, we consider it
                    # deleted and don't add it.
                    pass
Example #3
0
    def __init__(self, vcs_project, path):
        """
        Load the resource file for each enabled locale and store its
        translations in VCSEntity instances.
        """
        from pontoon.base import formats  # Avoid circular import.

        self.vcs_project = vcs_project
        self.path = path
        self.files = {}
        self.entities = {}

        db_project = vcs_project.db_project
        for locale in db_project.locales.all():
            resource_path = os.path.join(
                db_project.checkout_path,
                db_project.locale_directory_name(locale.code),
                self.path
            )
            try:
                resource_file = formats.parse(resource_path)
            except IOError:
                continue  # File doesn't exist, let's move on

            self.files[locale.code] = resource_file
            for index, translation in enumerate(resource_file.translations):
                # Create the entity if it doesn't yet exist, otherwise
                # append to it.
                if translation.key in self.entities:
                    vcs_entity = self.entities[translation.key]
                else:
                    vcs_entity = VCSEntity(
                        resource=self,
                        key=translation.key,
                        string=translation.source_string,
                        comments=translation.comments,
                        order=index
                    )
                    self.entities[vcs_entity.key] = vcs_entity

                vcs_entity.translations[locale.code] = translation