Jump to content

Guest Dynamic Language Selector


spacemonkey95
 Share

Recommended Posts

Hi,

 

Firstly, I have looked through the whole Multi-Language Support forum for an answer to my problem but I haven't found anything that's quite what I'm trying to achieve, so apologies if I'm duplicating here.

 

I have a website which is mostly viewed by guest users. I'm in the process of trying to add multi-language support so I can present text articles in English or French, depending upon the choice of the guest user. I have worked out how to use multi-language text fields in the backend Admin area, and I can manually switch between how these fields are displayed on the front end by editing the following line of code in my page:

 

$user->language = $languages->get("english");

 

Switching "english" to "french" there correctly changes the fields which follow into French. My problem is this: I want guest users to be able to click a button to select the language in which they view the site, but I don't want to use /en/ or /fr/ in the URL to achieve this. Essentially, I want a button which changes the line of code as above. Can anyone talk me through the code I need to include to achieve this (assuming it's possible)?

 

Oh, also I've read carefully through the Multi-Language Support API page and there's a paragraph which touches exactly on this area ("However, we are assuming you want to use language fields for the purpose of having multi-language versions of your site available to anonymous visitors. There are a large number of approaches you could take."), but unfortunately its link to examples of how to achieve it goes nowhere (https://processwire.com/api/multi-language-support/multi-language-fields/#examples). 

 

Thanks everyone ?

Link to comment
Share on other sites

Hello @spacemonkey95,

sorry for not being helpful, but you could build your own logic with:

  1. Language API
  2. Multi-Language Field Values
52 minutes ago, spacemonkey95 said:

I want guest users to be able to click a button to select the language in which they view the site, but I don't want to use /en/ or /fr/ in the URL to achieve this.

However I would recommend you not to do this. Having a translated website with no different URLs is bad for SEO and in my opinion a bad user experience, because the user always would have to switch first for having the right language.

If you really want to do this, maybe someone else has experience with this. ?

Regards, Andreas

  • Like 2
Link to comment
Share on other sites

I second that what @AndZyk said. It is not a good thing to omit the different URLs for each language. The term URL means Uniform resource locator, and should excactly do this. Locate a resource (for example the french version of an article). So if someone wants to bookmark the french version of an article on your site, he can not do it with your logic. Instead he has to switch to french everytime he visits.

Also from a SEO perspective this is very bad, because content in other languages can not be crawled.

Why don't you want to use language folders like /en/? What is the purpose?

Link to comment
Share on other sites

If you are looking for a example you could look here:

This website is build with Vue.js and has also a dynamic language switcher without page reload, but has no specific language URL, which is as mentioned bad for SEO.

You could add the language URL on switch with for example pushState, but in my opinion the language URL should be available without making a switch first. ?

Link to comment
Share on other sites

Hi guys,

 

Thanks for your replies. To be honest, once I thought about it, I can't remember why I was trying to avoid the language specific URLs so I've gone with that method after all. I found a snippet of code on one of the related threads in this forum and it seems to work perfectly so that's great. Thanks again ?

  • Like 2
Link to comment
Share on other sites

  • 1 year later...

I think, I have the similar question:

I need the language-settings being stored into the (guest-)users session. The reason is, the URLs will be openend via an QR-Code. I want the same QR-Codes leading to the (previewsly) selected language by the user.

Simply put:
1. the user openes one page via QR-Code. The language can be switched to the desired language.
2. whenever the user openes another page via a different QR-Code, I want processwire to remember the language settings. (depended on each user)

does this make any sense? or should i explain that in detail?

I already did create a question over here:
https://processwire.com/talk/topic/23299-one-url-for-multiple-languages/

Thanks for your help!!!!

Cheers
Stephan

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...