def save(self, locale):
        """
        Load the source resource, modify it with changes made to this
        Resource instance, and save it over the locale-specific
        resource.
        """
        if not self.source_resource:
            raise SyncError('Cannot save l20n resource {0}: No source resource given.'
                            .format(self.path))

        with codecs.open(self.source_resource.path, 'r', 'utf-8') as resource:
            new_structure = L20nParser().parse(resource.read())

        def attr_key(entity, attr):
            """Returns key for the attributes of entity."""
            return '.'.join([entity.id.name, attr.id.name])

        to_remove = []
        for res_entity in new_structure.body:
            if res_entity.type == 'Entity':
                entity_id = res_entity.id.name
                translations = self.entities[entity_id].strings
                comments = self.entities[entity_id].comments

                if not translations:
                    entity_idx = new_structure.body.index(res_entity)

                    for comment_entity in new_structure.body[entity_idx-len(comments):entity_idx]:
                        to_remove.append((new_structure.body, comment_entity))

                    # Checks if any attribute contains translation, if not
                    # then we can remove wole entity.
                    has_attributes = any([
                        bool(self.entities[attr_key(res_entity, a)].strings)
                        for a in res_entity.attrs
                    ])

                    if has_attributes:
                        res_entity.value = None

                    else:
                        to_remove.append((new_structure.body, res_entity))
                        continue

                if res_entity.value and res_entity.value.type == 'String':
                    res_entity.value.content[0] = translations[None]

                elif res_entity.value and res_entity.value.type == 'Hash':
                    res_entity.value.items = [
                        ast.HashItem(
                            ast.Identifier(locale.get_relative_cldr_plural(plural_relative_id)),
                            ast.String([value], value),
                            False
                        ) for plural_relative_id, value in translations.items()]


                for attr in res_entity.attrs:
                    key = attr_key(res_entity, attr)
                    attr_translations = self.entities[key].strings
                    if not attr_translations:
                        to_remove.append((res_entity.attrs, attr))
                        continue
                    attr.value.content[0] = attr_translations[None]

        for parent, entity in to_remove:
            parent.remove(entity)

        # Create parent directory if it doesn't exist.
        try:
            os.makedirs(os.path.dirname(self.path))
        except OSError:
            pass  # Already exists, phew!

        with codecs.open(self.path, 'w+', 'utf-8') as f:
            f.write(Serializer().serialize(new_structure))
            log.debug("Saved file: %s", self.path)
dataset/ETHPy150Open mozilla/pontoon/pontoon/sync/formats/l20n.py/L20NResource.save/original