wintercms/winter

CMS pages title translation broken

mjauvin opened this issue · 4 comments

Discussed in https://github.com/orgs/wintercms/discussions/1270

Originally posted by oim37 December 8, 2024
Hello,

I update winter to 1.2.7 with composer update and see that title, meta title, meta description allways whowing only on default language. when switching languages, they are always displayed in the default language and do not change according to the one specified in the admin panel. Thus, the search engine will calculate еhese pages are duplicates. I think this is a bug.

@bennothommo any chance fb88e6f would create such an issue?

@mjauvin if it were that commit, you'd be seeing exceptions thrown.

Looks like wintercms/storm@626409c broke Cms Page attributes translation.
( specifically the Halcyon/Model.php change to bindEventOnce() )

But if I look into Winter.Translate, I found this code block that makes no sense to me:

if ($locale != $this->translatableDefault) {
    $translated = $this->getAttributeTranslated($attr, $locale);
    $localeAttr = ($translated ?: $this->translatableUseFallback) ? $localeAttr : null;
}

ref. https://github.com/wintercms/wn-translate-plugin/blob/main/behaviors/TranslatablePage.php#L72-L86

It should be like this:

public function rewriteTranslatablePageAttributes($locale = null)
{   
    $locale = $locale ?: $this->translatableContext;

    foreach ($this->model->translatable as $attr) {
        $localeAttr = $this->translatableOriginals[$attr];
    
        if ($locale != $this->translatableDefault) {
            $translated = $this->getAttributeTranslated($attr, $locale);
            if ($translated) {
                $localeAttr = $translated;
            } elseif (!$this->translatableUseFallback) {
                $localeAttr = null;
            }
        }
        
        $this->model[$attr] = $localeAttr;
    }   
}   

I have NO IDEA how that could have worked before, but it did.

wintercms/wn-translate-plugin@db7f1ba resolves the issue, but I'd like to understand two things:

  • Why did that work before
  • what impact does the bindEventOnce() really has