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

Changes 13: New translation classes #6491

Merged
merged 23 commits into from
Jun 27, 2024

Conversation

bastianallgeier
Copy link
Member

@bastianallgeier bastianallgeier commented Jun 14, 2024

This PR …

Reasoning

The ContentTranslation class is one of our internal classes that still uses array props in the constructor and also has some logic that shouldn't be in there. To untangle the translation knot, it really helps to refactor this class to named properties and turn most of its methods into proxies to access the underlying version or language objects.

In order to turn this into a smooth transition, I've decided to extend the ContentTranslation class for now. This way, we can use it as a replacement for ContentTranslation in many parts already before we replace it later. We can also change methods more freely without affecting the CMS Models and their unit tests too drastically for now.

Features

  • New Kirby\Content\Translation class (to eventually replace Kirby\Content\ContentTranslation)
  • New Kirby\Content\Translations class to help in ModelWithContent::translations later and to provide a more type-safe collection for all translations.

The following changes to Translation will be new features as soon as it replaces the ContentTranslation class.

  • New Translation::version method to return the parent Version instance
  • New Translation::create method to setup a new translation from an array of fields.

Deprecated

  • Translation::code Use ::language()->code() instead
  • Translation::content Use ::version()->content()->toArray() instead
  • Translation::contentFile Use ::version()->contentFile() instead
  • Translation::exists Use ::version()->exists() instead
  • Translation::isDefault Use ::language()->isDefault() instead

Breaking changes

The following changes to the Translation class will be breaking changes as soon as it will replace the ContentTranslation class.

  • Translation::parent has been replace with Translation::model
  • Translation::update has been removed

Code coverage

No matter what I do, Translations::load is simply not covered and I don't know why.

Ready?

  • In-code documentation (wherever needed)
  • Unit tests for fixed bug/feature
  • Tests and checks all pass

For review team

  • Add changes & docs to release notes draft in Notion

@bastianallgeier bastianallgeier force-pushed the v5/changes/13-new-translation-classes branch 3 times, most recently from d0d6e8a to b5dc1c9 Compare June 14, 2024 11:28
src/Content/Translation.php Fixed Show fixed Hide fixed
src/Content/Translation.php Fixed Show fixed Hide fixed
src/Content/Translation.php Fixed Show fixed Hide fixed
src/Content/Translation.php Fixed Show fixed Hide fixed
src/Content/Translation.php Fixed Show fixed Hide fixed
@bastianallgeier bastianallgeier mentioned this pull request Jun 14, 2024
17 tasks
@distantnative
Copy link
Member

@bastianallgeier regarding your code coverage: none of your test methods says that it covers the load method. So even if the code does, it won't be reported as the test is limit to only cover the methods mentioned (and none mentions load).

@bastianallgeier
Copy link
Member Author

bastianallgeier commented Jun 14, 2024

@distantnative wait, am I missing something? https://github.com/getkirby/kirby/pull/6491/files#diff-be3909337c2195af14e3332b8945acaa88ae6801f3b6f92f4fa40343240c0747R111 I really think I'm going crazy here. I even tried to re-type that @Covers part in case I had an invisible character in it or some other typo that I just don't see.

@distantnative
Copy link
Member

distantnative commented Jun 14, 2024

@bastianallgeier sorry, my bad, mistook Translations::load() for Translation::load()

@distantnative
Copy link
Member

@bastianallgeier it seems tied to the method name. When I rename the method to loadd, it shows up fully covered.

Question: What is the reason for using the deprecated methods in the tests? https://github.com/getkirby/kirby/pull/6491/files#diff-ee064be1fccc6c3b78a97760793cd868737cdcf4273b70b1b9e61e189975b45aR63 failed for me when I replaced all deprecated methods with their suggested alternatives.

tests/Content/TranslationTest.php Outdated Show resolved Hide resolved
tests/Content/TranslationsTest.php Outdated Show resolved Hide resolved
@bastianallgeier
Copy link
Member Author

bastianallgeier commented Jun 15, 2024

So weird about the name! We could try what happens when we add a coverage ignore rule.

About the deprecated methods. We don't need to be that strict. My thought behind is that the translation class really acts more like glue for us between language, version and content. To repeat a lot of the version methods would be quite redundant. That's why I think we should encourage to prefer going through the versions. But that's totally up for discussions.

Did you specify the language when you used the alternative?

@distantnative
Copy link
Member

I'm for the depreciations. But we should adapt the tests then, shouldn't we? Currently the CI throws all the deprecation warnings.

@bastianallgeier
Copy link
Member Author

I have to be honest, I don't really know how to treat the depredations in unit tests so far

@distantnative
Copy link
Member

distantnative commented Jun 15, 2024

@bastianallgeier I am talking about replacing the deprecated code. Currently the test still use all the deprecated methods, e.g.

$this->assertSame('en', $translationEN->code());

should be changed to

$this->assertSame('en', $translationEN->language()->code());

etc.

@bastianallgeier bastianallgeier force-pushed the v5/changes/12-more-version-class-improvements branch from fc022e9 to 1afa5c5 Compare June 17, 2024 09:40
@bastianallgeier bastianallgeier force-pushed the v5/changes/13-new-translation-classes branch from 90ebb8f to 36d8df4 Compare June 17, 2024 09:40
@bastianallgeier
Copy link
Member Author

@distantnative I've replaced all deprecated methods in the unit tests.

@bastianallgeier bastianallgeier force-pushed the v5/changes/12-more-version-class-improvements branch from 1afa5c5 to b6a949b Compare June 19, 2024 10:45
@bastianallgeier bastianallgeier force-pushed the v5/changes/13-new-translation-classes branch from 0e54467 to 4648e2a Compare June 19, 2024 10:46
@bastianallgeier bastianallgeier mentioned this pull request Jun 20, 2024
17 tasks
@bastianallgeier bastianallgeier force-pushed the v5/changes/13-new-translation-classes branch from 4648e2a to 8f94357 Compare June 20, 2024 09:33
@bastianallgeier bastianallgeier force-pushed the v5/changes/12-more-version-class-improvements branch from 6c03ae2 to 4b53a08 Compare June 20, 2024 09:46
@bastianallgeier bastianallgeier force-pushed the v5/changes/13-new-translation-classes branch from 8f94357 to 84cdf0a Compare June 20, 2024 09:47
@bastianallgeier bastianallgeier force-pushed the v5/changes/12-more-version-class-improvements branch from 4b53a08 to 3bb3d23 Compare June 21, 2024 09:34
@bastianallgeier bastianallgeier force-pushed the v5/changes/13-new-translation-classes branch 2 times, most recently from c62e360 to 78b12f5 Compare June 21, 2024 10:20
src/Content/Translation.php Outdated Show resolved Hide resolved
src/Content/Translation.php Outdated Show resolved Hide resolved
src/Content/Translation.php Outdated Show resolved Hide resolved
src/Content/Translation.php Outdated Show resolved Hide resolved
src/Content/Translation.php Outdated Show resolved Hide resolved
src/Content/Translation.php Outdated Show resolved Hide resolved
src/Content/Translations.php Show resolved Hide resolved
src/Content/Translations.php Outdated Show resolved Hide resolved
@bastianallgeier bastianallgeier force-pushed the v5/changes/12-more-version-class-improvements branch from cedd533 to a6ea212 Compare June 24, 2024 09:29
@bastianallgeier bastianallgeier force-pushed the v5/changes/13-new-translation-classes branch from 78b12f5 to 241501d Compare June 24, 2024 09:29
src/Content/Translation.php Outdated Show resolved Hide resolved
src/Content/Translation.php Outdated Show resolved Hide resolved
src/Content/Translation.php Outdated Show resolved Hide resolved
src/Cms/Helpers.php Outdated Show resolved Hide resolved
tests/Content/TranslationTest.php Outdated Show resolved Hide resolved
tests/Content/TranslationTest.php Outdated Show resolved Hide resolved
Base automatically changed from v5/changes/12-more-version-class-improvements to v5/develop June 25, 2024 08:24
@bastianallgeier bastianallgeier marked this pull request as ready for review June 25, 2024 08:37
@bastianallgeier bastianallgeier added this to the 5.0.0-alpha.2 milestone Jun 25, 2024
Copy link
Member

@lukasbestle lukasbestle left a comment

Choose a reason for hiding this comment

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

Two methods of ContentTranslation that Translation does not implement anymore (and doesn't need to) are parent() and update(). In order to make the transition smoother, we need to find bugs early where we maybe still rely on these methods. So I suggest to add overrides for these two methods to the Translation class that throw an exception.

With that I think we can finally merge this.

@bastianallgeier bastianallgeier merged commit 09632f3 into v5/develop Jun 27, 2024
9 checks passed
@bastianallgeier bastianallgeier deleted the v5/changes/13-new-translation-classes branch June 27, 2024 08:20
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.

3 participants