Jump to content

Recommended Posts

Posted

Hi all!

i have noticed that if enable the cache (for example on homepage), if I switch language the page is always the same, so i imagine that cache file is the same for any language.

I wonder if there is any option that can save one cache file for each language.

Alessio 

Posted

Template caching is language aware (and it includes the language as part of the cache file's id), but you'd have to have some aspect of the request determine the language before rendering the page. Otherwise there's no way to connect that cache file with the request. The simplest way to do that is to use the LanguageSupportPageNames module, to ensure that your homepage (for example) has a different URL for each language. If you are determining language from the hostname (i.e. en.domain.com, it.domain.com, etc.), then you'd have to have a before(Page::render) hook that sets the $user->language based on the hostname. I'm not sure what method you are using to determine language, so let me know and I can give you a better example. 

  • Like 2
  • 1 year later...
Posted

If you are determining language from the hostname (i.e. en.domain.com, it.domain.com, etc.), then you'd have to have a before(Page::render) hook that sets the $user->language based on the hostname.

Hello.

I'm trying to implement language switching by using GET-parameter. Can you help me to understand how hook works?

if ( $_GET['lang'] == 'en'){
    wire()->addHookBefore('Page::render', function($event){
        $user->language = $languages->get("en");
        $user->save();
    });
}

What am I doing wrong?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...