If you have a multi language site, and change languages, the menu is already cached, thus it can not display the translated version. This simple patch makes the menu cache locale aware. Do I need to file the same patch against HEAD? 'Cos it applies, too.

CommentFileSizeAuthor
menu_locale.patch522 byteschx

Comments

dries’s picture

Isn't it better to flush the menu cache when someone (or the admin) switches languages? Keeps the cache size down.

chx’s picture

There could be several points where the language is changed. i18n for example displays a language selection block which lets you switch anytime. Thus I think this solution is the best.

gábor hojtsy’s picture

See also this issue, which is still (again) open. The locale is also changed, when the admin changes it as the default on the admin interface, and the menu cache needs to be flushed then, and the admin needs to be redirected. I don't know how these problems are solved currently, so I would only be able to submit a placebo patch to make that issue pop up again...

Bèr Kessels’s picture

I solved it by adding some logic to the swithcer function in i18n:
when a language is switched the cache is flushed.

The negative side of this, is that if you have hundred various roles of users reading English and one switching to German, the complete cahce is flushed.
But then again, who has so many roles, that this might become an issue?

dries’s picture

I just fixed bug 11312.

I don't see what's wrong with invalidating the user's menu cache when he or she switches language. Just do:
cache_clear_all("menu:$user->uid");

dries’s picture

jose reyero’s picture

This is needed also for i18n.

Invalidating cache is not a solution here, as we would need to do it also for anonymous users.

So I think this is a simple solution and will work fine for both cases, user/locale and i18n.

chx’s picture

Bèr Kessels’s picture

I found out what is wrong with this:

Swithcing and cache are two completely differetn things:

The language is a per-session setting.
The cache is a per-role setting.

So any user can switch langauge on any moment, resulting in a cahce that will get flushed on nearly every page-load. And since roles and sessions are tow different thingsm we should not flush a role based cache because a variable in the session changes.

The only correct option would be to have per-locale cache. (as per Jose's patch)

Bèr Kessels’s picture

Correction,
It was not José that submitteed the patch for locale aware menu's but Károly Négyesi, I got confused because José was the last to comment on that patch.

moshe weitzman’s picture

i can't make heads or tails of this patch request. it seems that some folks are confusing menu cache and page cache. and we don't even have a role cache.

dries' question remains unanaswered. why can we not just rebuild a user's menu cache when needed?

jose reyero’s picture

why can we not just rebuild a user's menu cache when needed?

This way you cannot have menus in multiples languages for anonymous users, unles they're not cached at all.

moshe weitzman’s picture

Aha! Makes sense now. +1 for this simple patch.

killes@www.drop.org’s picture

I agree, this should get patched. Still applies.

Stefan Nagtegaal’s picture

Tested against 4.6 RC I and works perfectly!
+1 for applying this bug-fix..

Bèr Kessels’s picture

Josés latest comment tels in much less wording what i tried to explain too.

Still +1 from me, since with i18n (and other possible language modules) you cannot simply flush the cache.

This patch is simple, clean and only adds one row per language to your cache table. That cannot be a problem, now, can it?

elfur’s picture

I'd like to +1 this change.
I too have a dual language website where changing the language in the language block does not change the language of the navigation block, while all other blocks change.

But what also happens is that on my user profile page I can select which language are assigned to the user, and when I swithced that the first time, the language of the navigation block got switched to the selected language of the web - however when I changed that user profile setting back to my preferred language, the navigation block does not change back with it. Infact, when I then change the language in the language block, the navigation does not change back to what it was stuck at before *shrug*.

I hope that does make sense to anyone.

/me heads over to try that patch to see if it fixes this annoying "feature"

thanks
elfur
http://elfur.is

chx’s picture

Priority: Normal » Critical

I have bumped this to critical status, I feel this very important, very simple, non evasive.

dries’s picture

Anonymous’s picture