Post by MadMcJack » Fri Aug 07, 2020 7:57 pm

Currently it seems language is being set through a session and has to be changed through POST method to the languages module with a redirect page.

I would like a way to bypass (and force session update) by entering a direct URL like:

index.php?route=common/home&lang=en
index.php?route=common/home&lang=fr

After this works it will be possible to make language specific SEO URL's using the htaccess file.

I am having trouble finding the (most logical) place to implement this.

Any help is appreciated!

Newbie

Posts

Joined
Fri Aug 07, 2020 6:41 pm

Post by letxobnav » Fri Aug 07, 2020 10:29 pm

best way to do this is not htaccess but via startup.php where the language is set currently to take the language get variable lang and override the session/cookie etc. to set the requested language.
To set the lang get variable you need to adjust the url class so that ?lang=xx or &lang=xx is added to each url you put in your html based on the current language set.

For seo urls you can also just use a virtual language indicator like domain/en/... or domain/fr/... etc. but the same principle applies.
You need to identify the language indicator in startup.php, use it and subsequently discard it and you need to set the language indicator on all urls you put out.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by MadMcJack » Sat Aug 08, 2020 1:51 am

Thank you! I was too focused on checking the system/ directory and missing the catalog/controller/startup/startup.php!

You are right about better using /lang/ syntax instead of lang= as get method.

I am now using something like this:

Code: Select all

if ( preg_match('^/en/', $this->request->server['REQUEST_URI']) ) {
  $code = 'en-gb';
}
Which works OK.

If I may ask some more... Any pointers are welcome for where to best adjust:

1) The default SEO rewrites for products/categories/information so they use this /lang/ subdirectory (entering a directory in seo url is not allowed it seems)
2) The non SEO index.php?route=xx/xx so they can be rewritten to /lang/xx

Newbie

Posts

Joined
Fri Aug 07, 2020 6:41 pm

Post by letxobnav » Sat Aug 08, 2020 9:37 am

1) The default SEO rewrites for products/categories/information so they use this /lang/ subdirectory (entering a directory in seo url is not allowed it seems)
2) The non SEO index.php?route=xx/xx so they can be rewritten to /lang/xx
No, you do not enter the language indicator in the seo keywords.
the seo_url class splits the url in checks separated by / so a / in the keyword is not allowed.
In the url class or as I do it in the seo_url class, you determine which language you are in and based on that stick the indicator at the front of the url returned.

so in short for english for instance
writing the urls:
1) do te normal rewrite in seo_url
2) if current language is english prepend en/ to the url, if it is french prepend fr/ before returning the url (between domain and url if you use absolute urls).

reading the urls:
1) check if en/ or fr/ is in the url at the first 3 positions
2) if so, set the language accordingly bypassing all other language logic as it overrides those.
3) remove the en/ or fr/ from the $this->request->server['REQUEST_URI'] variable as it is no longer needed and actually would be picked up by the seo_url class as a keyword (that class sees every value between / as a keyword to be checked) which does not exist.

you can add the language indicator to non-seo urls but why would you want to?
These indicators are purely for search engines which would otherwise always receive your pages in your default language regardless of the language of the url. Since there is no need to make pages which you do not want to be indexed (account, checkout,etc.) seo, you also do not need to add a language indicator to those.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by MadMcJack » Sat Aug 08, 2020 2:05 pm

Thanks for the pointers. Makes sense what you all say. I'll see what I can do ;)

Newbie

Posts

Joined
Fri Aug 07, 2020 6:41 pm
Who is online

Users browsing this forum: No registered users and 25 guests