getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.32k stars 168 forks source link

`ModelwithContent::setTranslations()` and `ModelwithContent::translations()` - duplicate code? #3509

Closed distantnative closed 3 years ago

distantnative commented 3 years ago

Seems like both methods are almost doing the same thing. Why have we implemented this in two different methods?

afbora commented 3 years ago

IMO It doesn't duplicate, but it looks like code that does the same thing a little differently. Just the source they loop in is different but I think it can be combined as well.

distantnative commented 3 years ago

True.

One is setting translations only if any have been passed to the constructor (setTranslations). The other one sets them if none have been set so far/via the constructor (translations).

@bastianallgeier Did we split this for performance reasons? e.g. if none are passed to the constructor, only set them if ->translations() is even called

bastianallgeier commented 3 years ago

They both need to exist.

setTranslations is used when you create virtual pages for example. In this case each translation is an array of props.

The translations getter is loading translations from kirby->languages() if they are not set yet and each translation is a language object.

I don't see how we could improve this a lot without making it more complex.