Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add translation_imported signal #3

Merged
merged 3 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
"redhat.vscode-yaml",
"tamasfe.even-better-toml",
"the-compiler.python-tox"
]
],
"settings": {
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
}
}
}
}
}
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,14 @@ flowchart LR

```

## Signals

This app provides a single `wagtail_localize.signals.translation_imported`
signal that is sent when translation are imported from Smartling.

## Signals
Signal kwargs:

<!-- TODO -->
- `translation_imported`
- `sender`: The `wagtail_localize_smartling.models.Job` class
- `instance`: The `Job` instance for which translation are being imported
- `translation`: The `wagtail_localize.models.Translation` instance the translations are being imported to
- `target_instance`: The model instance that `translation` is for (i.e. the instance returned by `translation.get_target_instance()`)
zerolab marked this conversation as resolved.
Show resolved Hide resolved
46 changes: 46 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,49 @@ reportUnnecessaryTypeIgnoreComment = true
# Make sure we're checking against the minimum supported Python version by
# default. CI will check against all supported versions for us.
pythonVersion = "3.8"


[tool.ruff]
zerolab marked this conversation as resolved.
Show resolved Hide resolved
extend-exclude = [
"LC_MESSAGES",
"locale",
]

[tool.ruff.lint]
select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"DJ", # flake8-django
"E", # pycodestyle errors
"F", # pyflakes
"I", # isort
"RUF100", # unused noqa
"S", # flake8-bandit
"UP", # pyupgrade
"W", # warning
]
fixable = [
"C4",
"E",
"F",
"I",
"UP",
]

[tool.ruff.lint.isort]
lines-after-imports = 2
lines-between-types = 1


[tool.ruff.lint.per-file-ignores]
"tests/**/*.py" = [
"S101", # asserts allowed in tests
"ARG", # unused function args (pytest fixtures)
"FBT", # booleans as positional arguments (@pytest.mark.parametrize)
"PLR2004", # magic value used in comparison
"S311", # standard pseudo-random generators are not suitable for cryptographic purposes
]


[tool.ruff.format]
docstring-code-format = true
43 changes: 0 additions & 43 deletions ruff.toml

This file was deleted.

1 change: 0 additions & 1 deletion src/wagtail_localize_smartling/signals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.dispatch import Signal


# TODO send this
translation_imported = Signal()
10 changes: 9 additions & 1 deletion src/wagtail_localize_smartling/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

from django.db import transaction
from django.utils import timezone
from wagtail_localize.models import Translation

from . import utils
from .api.client import client
from .api.types import JobStatus
from .signals import translation_imported


if TYPE_CHECKING:
Expand Down Expand Up @@ -183,7 +185,7 @@ def _download_and_apply_translations(job: "Job") -> None:
)

try:
translation = job.translations.get(
translation: Translation = job.translations.get(
target_locale__language_code=utils.format_wagtail_locale_id(
smartling_locale_id
)
Expand All @@ -197,4 +199,10 @@ def _download_and_apply_translations(job: "Job") -> None:
with translations_zip.open(zipinfo) as f:
po_file = polib.pofile(f.read().decode("utf-8"))
translation.import_po(po_file)
translation_imported.send(
sender=Job,
instance=job,
translation=translation,
target_instance=translation.get_target_instance(),
)
logger.info("Imported translations for %s", translation)
5 changes: 1 addition & 4 deletions tests/status/test_status_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ def test_everything_working(client, superuser, smartling_project):
# Project metadata
assert f"Project ID {smartling_project.project_id}" in text
assert f"Project name {smartling_project.name}" in text
assert (
f"Source locale {smartling_project.source_locale_description}"
in text
)
assert f"Source locale {smartling_project.source_locale_description}" in text

# Source locale
assert "The source locale is compatible with Smartling" in text
Expand Down
Loading