The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Changing a link based on a user's language setting

4 posters

Go down

Solved Changing a link based on a user's language setting

Post by Ayushka December 10th 2023, 2:28 am

Hello!

I'm not sure if this is possible, but is there a way that a link would change from the original URL address to a different one for users who have a different language set in their options?
For example, I'd have a clickable icon in my forum's header that'd redirect you to some English website, but for my German users I'd like that icon to lead to a German website.
I hope I explained it properly and didn't confuse you lol
Forum version: AwesomeBB

Thank you in advance!


Last edited by Ayushka on December 10th 2023, 3:27 am; edited 1 time in total
Ayushka
Ayushka
New Member

Posts : 7
Reputation : 1
Language : en

https://help.forumotion.com/

Back to top Go down

Solved Re: Changing a link based on a user's language setting

Post by matt4116 December 10th 2023, 3:22 am

Hello, Ayushka.

are you referring to the url address of your forum? Here is a thread that might help you. hope you figure out the problem you are having. https://help.forumotion.com/t59451-frequently-asked-questions
matt4116
matt4116
New Member

Posts : 7
Reputation : 1
Language : english

Back to top Go down

Solved Re: Changing a link based on a user's language setting

Post by skouliki December 10th 2023, 8:08 am

Hello
You want an icon to be redirect to 2 pages depend the language?
I dont know if it possible by adding an onclick event to the image:
skouliki
skouliki
Manager
Manager

Female Posts : 15391
Reputation : 1709
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Solved Re: Changing a link based on a user's language setting

Post by Razor12345 December 10th 2023, 10:23 am

Good afternoon!

AP - Modules - Javascript codes management - Create new Javascript

Title: any
Placement: In all the pages
Javascript code:

Code:
jQuery(document).ready(function() {
  const language = navigator.language || navigator.userLanguage;
  const button = document.querySelector('.button__site');
  if (button) {
  button.addEventListener('click', function(e) {
    e.preventDefault();
    if (language === 'de-DE') window.location.href = 'https://www.example.com';
    else window.location.href = 'https://www.anotherexample.com';
  });
  }
});

Save.

Code:
const language = navigator.language || navigator.userLanguage;
- on this line we recognise the language of the user's browser.

Code:
const button = document.querySelector('.button__site');
- on this line we are looking for a button that responds to go to another site. My button has class
Code:
.button__site
. Yours may have a different class.

Code:
if (language === 'de-DE') window.location.href = 'https://www.example.com';
- If the user's browser language is German, the user will go to the https://www.example.com address when clicking on the button. Other users will be directed to the site at https://www.anotherexample.com



Changing a link based on a user's language setting Screen51
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1583
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine

skouliki, TonnyKamper and Jucarese like this post

Back to top Go down

Solved Re: Changing a link based on a user's language setting

Post by skouliki December 22nd 2023, 7:44 am

hello

if your request is completed/answered, please mark it as Solved.
skouliki
skouliki
Manager
Manager

Female Posts : 15391
Reputation : 1709
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Solved Re: Changing a link based on a user's language setting

Post by Razor12345 January 2nd 2024, 10:19 am

Good afternoon!

It's been over two weeks now. We still have not received a reply from the author.
I am closing the topic and moving it to the archive.

If your problem is not solved - write me a private message and I will open this topic for further help.

Problem solved & topic archived.
Please read our forum rules: ESF General Rules


Changing a link based on a user's language setting Screen51
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1583
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum