Problem/Motivation

Same problem as #2716019: View titles in breadcrumb and metatag title don't get properly translated

From a fresh Drupal install.

  • Enable translations and add a language.
  • Configure 2 views pages on the paths: example, /test1 and /test1/test2
  • Add path aliases for the other language: example, /testfr1 and /testfr1/testfr2
  • Translate the views in the other language
  • go to the following paths /test1, /test1/test2, /testfr1, /testfr1/testfr2 and see that it is not the correct language used for breacrumb part

Patch from comment #2716019-67: View titles in breadcrumb and metatag title don't get properly translated fixed the issue for core but not for easy breadcrumb.

Proposed resolution

None yet.

Remaining tasks

  1. Find a solution
  2. Make a patch

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Grimreaper created an issue. See original summary.

godotislate’s picture

The core patch from #2716019-67: View titles in breadcrumb don't get properly translated returns the title as a \Drupal\Core\Render\Markup object, which needs to be accounted for in \Drupal\easy_breadcrumb\EasyBreadcrumbBuilder::getTitleString().

Patch attached. Note that the core patch needs to be applied as well. Patch includes a simple update to the kernel tests, but does not include test for the title being correctly displayed in the correct language.

godotislate’s picture

Status: Active » Needs review
Greg Boggs’s picture

Thanks!

mibfire’s picture

Assigned: Unassigned » mibfire

I started working on issue review.

mibfire’s picture

Assigned: mibfire » Unassigned
Status: Needs review » Reviewed & tested by the community

I have tested it with latest Drupal 8.7.6 and it is working. Note that it was not even working with default language, not just with translation!

tatarbj’s picture

Shouldn't we cover other cases in tests too then? I'm fine with marking it RTBC now, but maybe a follow-up issue would be beneficial.

ohabara’s picture

#2 doesn't work with newest core patch 2716019 - View titles in breadcrumb don't get properly translated - #77 because title was changed from \Drupal\Core\Render\Markup to Drupal\views\Render\ViewsRenderPipelineMarkup

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 3072117-3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mirom’s picture

Status: Needs work » Needs review
FileSize
4.33 KB

Hi folks, it seems that #13186043 changed direction. Here is a patch which should work more flexible regarding Markup classes. Credit (if issue is closed) should go to wrany as well, who contributed patch in some invisible comment.

godotislate’s picture

// If title is object then try to render it.
+    if (is_object($title)) {
+      $titleClass = get_class($title);
+      if (in_array('render', get_class_methods($titleClass))) {
+        $title = $title->render();
+      }
+      else {
+        $title = (string) $title;
+      }
+      $title = strip_tags($title);
     }

I think that just checking for instances of MarkupInterface and converting to string should do what's required. The render() method gets invoked when converting TranslatableMarkup to string anyway, so it doesn't need to be called directly.

if ($title instanceof \Drupal\Component\Render\MarkupInterface) {
  $title = strip_tags((string) $title);
}
mirom’s picture

Thanks for review. Could you please point out where typecasting to string calls render function? I'm unable to find it. __toString function from FormattableMarkup is calling simpler code than render function.

godotislate’s picture

\Drupal\Core\StringTranslation\TranslatableMarkup uses \Drupal\Component\Utility\ToStringTrait, and it's there.

I don't think the other core MarkupInterface classes use render().

mirom’s picture

Simplified patch from #11.

strozx’s picture

If I understood the problem correctly it looks like it works. But I will leave this open so that others can test and confirm if it works like it should.
Regards!

jtriguero’s picture

In patch 14, the FormattableMarkup import and ViewsRenderPipelineMarkup import should be removed. On the other hand, I am attaching the patch for the current version (8.x-1.12). I know this is not the normal procedure, but I needed a patch and I attach it in case anyone finds it useful.

Greg Boggs’s picture

Status: Needs review » Fixed

Thanks Folks!

Greg Boggs’s picture

Status: Fixed » Needs work

Hrm, after adding this fix, the tests are now failing in the dev branch. Anyone have any ideas? :)

https://www.drupal.org/pift-ci-job/1711952

Grimreaper’s picture

Hello,

I think you commited only the change in the test file and not the whole patch.

https://git.drupalcode.org/project/easy_breadcrumb/commit/28a6a21 is only a one line change.

  • Greg Boggs committed cb5fb3f on 8.x-1.x authored by jtriguero
    Issue #3072117 by mirom, godotislate, jtriguero, Greg Boggs, Grimreaper...
Greg Boggs’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.