Skip to content

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