Closed (fixed)
Project:
Admin Toolbar
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
1 Jul 2016 at 08:21 UTC
Updated:
8 Oct 2019 at 09:43 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
miiimoooI am attaching what is by no means a solution to the problem. I've tracked this down to where the menu items are added in admin_toolbar_tools. Menu items that are translated correctly are stored as (serialized) TranslateableMarkup in the menu table and are then translated at runtime to teh correct current language. The current code just stores the translation at the time of the menu tree build as string to the db. So they are not translated when viewed in a different language.
The patch is using
t($var)which is probably in most cases not correct. But I am not sure how to access config translation. Maybe some expert in (config) translation can advise.Comment #3
miiimooo(duplicate post)
Comment #4
nghai commented@miiimooo Is this problem solved ? Because the problem is still there with Release 8.x-1.17.
Comment #5
chegor commentedPatch works for me in 8.x-1.17.
Comment #6
mrtndlmt commentedThanks for the patch! Works for me!
Comment #7
ckaotik\Drupal::entityTypeManager()->getStorage('node_type')->loadMultiple()already returns the localized title/description when using configuration translation. Therefore,t($type->label())can lead to unexpected side effects, e.g. declaring already translated configuration titles as source strings for interface translation. As far as I know, we should not run the returned label through translation again.This does create the effect, however, that links are always displayed in the interface language used during menu/links cache rebuild. I don't quite know how to fix this, though ...
Comment #8
bdominguez commentedI have the same problem. In my case, patch #5 doesn't work with Drupal 8.2.6.
It's a critical issue for multilanguage sites.
Edit: I expand my answer. It works but only if I do "Rebuild menu". But to display in each language I have to change interface language and then "Rebuild menu". It only works in the current language, to see it in another language I have to do "Rebuild menu" again. And If I do "Flush all caches" I will get the menu in other language (the site default language).
Comment #9
ckaotikThe problem is that we can't use string translation (where translation happens very late, during rendering => post caching) because the entities use configuration translation (where translation happens very early, when loading the configuration => pre caching). This in combination with MenuLinkDefault/MenuLinkBase caching everything statically causes issues. We'd probably need a cache context of
languages:language_interfaceto get this working.I can see two options on how we could resolve this, both are neither nice nor short: Either provide a new MenuLink type that can cache by language context, or create a new StringTranslator for the TranslationManager that pulls translations from configuration and would allow us to use TranslatableMarkup as suggested in hook_menu_links_discovered_alter. The first should be the easier one and might be avoided if we could manage to get a Core-patch that allows definitions of MenuLinkDefault to provide caching information, maybe via
metadata?Comment #10
spadxiii commentedIt looks like this patch is already included in the submodule admin_toolbar_tools.
Comment #11
Johnny vd Laar commentedI agree that this possibly isn't the best way to translate these items. But I also needed Vocabularies and Menu items to be translated. So I've passed these through the t-function as well.
Comment #12
Johnny vd Laar commentedAnd a patch for everyone on 8.x-1.19
Comment #13
romainj commentedI think that we need a patch even if it's an ugly one:) I created it according to the latest dev version.
Comment #15
romainj commentedCommitted in latest dev version. Thanks to all.
Comment #16
romainj commentedComment #21
adriancidRerolling the patch.
This was changed in http://cgit.drupalcode.org/admin_toolbar/diff/admin_toolbar_tools/admin_...
Comment #23
adriancidComment #25
jean-anx commentedI edited the patch #21 because it doesn't work on Admin toolbar 1.27 version. Feel free to review it !