in src/wagtail_localize_smartling/views.py [0:0]
def get_context_data(self, **kwargs):
try:
project = Project.get_current()
except Exception:
logger.exception("Failed to get current Smartling project")
project = None
context: dict[str, Any] = {
"project": project,
}
if project:
# Link to the project in the Smartling dashboard
context["project_url"] = format_smartling_project_url(project)
# List the target locales of the Smartling project
context["target_locales"] = [
{
"description": tl.description,
"enabled": tl.enabled,
}
for tl in project.target_locales.all()
]
# Source locale information
context["wagtail_source_locale"] = get_wagtail_source_locale(project)
suggested = suggest_source_locale(project)
if suggested is not None:
try:
locale = Locale.objects.get(language_code=suggested[0])
except Locale.DoesNotExist:
locale = None
context["suggested_source_locale_exists"] = locale is not None
context["suggested_source_locale"] = {
"language_code": suggested[0],
"label": suggested[1],
}
if locale is not None:
context["suggested_source_locale"]["url"] = reverse(
"wagtaillocales:edit", kwargs={"pk": locale.pk}
)
else:
context["suggested_source_locale"] = None
context["suggested_source_locale_exists"] = False
return super().get_context_data(**context)