Language System on site

Hi, guys! I would like to get interested. How can I make a language selection button and a shift action on the index.php main page? I have a lang.php file in my site’s directory. There is also another directory with ru.php & eng.php files

lang.php:

<?php switch($_GET['lang']) : default: include('lang/ru.php'); break; case 'ru': include('lang/ru.php'); break; case 'eng': include('lang/eng.php'); break; endswitch; ?>

ru.php:

<?PHP $lang['title'] = 'Статус Догги'; // и тд. ?>

eng.php:

<?PHP $lang['title'] = 'Doggy Status Page'; // и тд. ?>

I’m not sure how to do that. One thing I do know is that you could integrate Google Translate into the site and add the button from them.

Please, give example code:)

index.php should send an HTML file with the language selection page. After that, you would want to redirect user to a specific page like my-page.com?lang=eng or my-page.com?lang=${lang} with ${lang} as the language that the user picked.

This tutorial from w3schools should be ok if u want to do that sort of thing. Click here

1 Like

You could do a if in PHP.

    if($_GET["lang"] === "en") {
             (english code here)
       }

So when they visit example.com/home?lang=en it will be in english.