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.
The forum of the forums
4 posters

    Changing a link based on a user's language setting

    Ayushka
    Ayushka
    New Member


    Posts : 7
    Reputation : 1
    Language : en

    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
    matt4116
    matt4116
    New Member


    Posts : 7
    Reputation : 1
    Language : english

    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
    skouliki
    skouliki
    Manager
    Manager


    Female Posts : 15311
    Reputation : 1705
    Language : English,Greek
    Location : Greece

    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:

    Razor12345
    Razor12345
    Support Moderator
    Support Moderator


    Male Posts : 1575
    Reputation : 266
    Language : Ukr, Rus, Eng
    Location : Ukraine

    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

    skouliki, TonnyKamper and Jucarese like this post

    skouliki
    skouliki
    Manager
    Manager


    Female Posts : 15311
    Reputation : 1705
    Language : English,Greek
    Location : Greece

    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.

    Razor12345
    Razor12345
    Support Moderator
    Support Moderator


    Male Posts : 1575
    Reputation : 266
    Language : Ukr, Rus, Eng
    Location : Ukraine

    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

      Current date/time is September 22nd 2024, 9:16 pm