Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This is the best module ever.
I have admin_toolbar and extras enabled. In the Swedish drop down for Content (Innehall) -> Add content (Lag till..) -> I cannot get the content type names translated. Although they are translated correctly when I got to the /node/add page.
I am not sure this is an admin toolbar problem but I thought I have to start somewhere.
Comment | File | Size | Author |
---|---|---|---|
#25 | admin_toolbar-names_not_translated-2759135-25-d8.patch | 2.64 KB | Jean Anx |
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 CreditAttribution: nghai commented@miiimooo Is this problem solved ? Because the problem is still there with Release 8.x-1.17.
Comment #5
chegor CreditAttribution: chegor as a volunteer commentedPatch works for me in 8.x-1.17.
Comment #6
mrtndlmt CreditAttribution: 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 CreditAttribution: 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_interface
to 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 CreditAttribution: SpadXIII at ezCompany commentedIt looks like this patch is already included in the submodule admin_toolbar_tools.
Comment #11
Johnny vd Laar CreditAttribution: Johnny vd Laar at ezCompany 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 CreditAttribution: Johnny vd Laar at ezCompany commentedAnd a patch for everyone on 8.x-1.19
Comment #13
romainj CreditAttribution: romainj as a volunteer 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 CreditAttribution: romainj as a volunteer commentedCommitted in latest dev version. Thanks to all.
Comment #16
romainj CreditAttribution: romainj as a volunteer 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 CreditAttribution: Jean Anx commentedI edited the patch #21 because it doesn't work on Admin toolbar 1.27 version. Feel free to review it !