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

Make related models fields translatable #11

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ilya-likhota
Copy link
Collaborator

@ilya-likhota ilya-likhota commented Mar 5, 2024

The aim of the PR is to translate related models fields at once with translation of root model.
Here is a use case that describe the changes:

    def test_nested_translatable_fields_queryset(self):
        firm = FirmFactory()
        profile = ProfileFactory(
            firm=firm,
            title="Title",
            translations={
                "fr_ca": {
                    "title": "FR Title",
                },
            },
        )
        person = PersonFactory(
            first_name="Jane",
            last_name="Doe",
            firm=firm,
            profile=profile,
            translations={
                "fr_ca": {
                    "first_name": "FR Jane",
                    "last_name": "FR Doe",
                },
            },
        )

        person = Person.objects.filter(id=person.id).first()
        self.assertEqual(person.first_name, "Jane")
        self.assertEqual(person.last_name, "Doe")
        self.assertEqual(person.profile.title, "Title")

        translation.activate("fr_ca")
        person = Person.objects.filter(id=person.id).first()
        self.assertEqual(person.first_name, "FR Jane")
        self.assertEqual(person.last_name, "FR Doe")
        self.assertEqual(person.profile.title, "FR Title")  # Related models fields should be translated

@ilya-likhota ilya-likhota self-assigned this Mar 5, 2024
@ilya-likhota ilya-likhota marked this pull request as draft March 5, 2024 19:27
@ilya-likhota ilya-likhota changed the title Add collect_related_translatable_instances Make related models fields translatable Mar 6, 2024
Copy link

@hexvolt hexvolt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this support a chain only of 2 models? What if you have tranlatable_model.translatable_model.translatbale_model?

Or translatabale_model.regular_model.translatable_model?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants