def _initial_sync()

in src/wagtail_localize_smartling/sync.py [0:0]


def _initial_sync(job: "Job") -> None:
    """
    For jobs that have never been synced before, create the job in Smartling and
    add the PO file from the TranslationSource.

    Also add Visual Context for Smartling CAT, if a callback to get that is configured
    """
    logger.info("Performing initial sync for job %s", job)

    # Create the job in the Smartling API
    target_locale_ids = [
        utils.format_smartling_locale_id(lc)
        for lc in job.translations.values_list(
            "target_locale__language_code", flat=True
        )
    ]

    job_data = client.create_job(
        job_name=job.name,
        target_locale_ids=target_locale_ids,
        description=job.description,
        reference_number=job.reference_number,
        due_date=job.due_date,
    )

    job.translation_job_uid = job_data["translationJobUid"]
    job.status = job_data["jobStatus"]

    now = timezone.now()
    job.first_synced_at = now
    job.last_synced_at = now

    job.full_clean()
    job.save()

    # Create a Job Batch so we can upload Files without race conditions
    # in associating them with a Job (even a single PO file can go in a batch)
    batch_uid = client.create_batch_for_job(job=job)

    # Upload the TranslationSource's PO file to the Batch in Smartling
    file_uri = client.upload_files_to_job_batch(
        job=job,
        batch_uid=batch_uid,
    )

    # Add the file URI to the Job
    job.file_uri = file_uri
    job.save(update_fields=["file_uri"])

    # Add context to the job (if settings.VISUAL_CONTEXT_CALLBACK is defined)
    client.add_html_context_to_job(job=job)