PHP Multi Language Website Tutorial: Create Dynamic Website In 20 Minutes

In today video, you will learn how to create multi-language website in PHP, first I’m going to explain about three different ways on how you can do it And then I’m going to show you step-by-step how to write the code and use the easiest way so if you want to learn about those three steps stay with me Hey, what’s up guys Senaid here from the place where I help others to become a web developer much easy and faster than they will do it on their own, so if that’s something that interests you consider subscribing ->> So before we start writing actually any code I want that to actually know about three different ways that you can use So before you do any coding you need to decide which one you are going to use so in this video We are going to use the first one its PHP arrays Basically that way is the simplest you are going to create just different files Contain each language that you have and then we would just from associative array call the key And then we will have it translated Get text is the another version, is quite hard You will need to know how to set up your server need to know how to create that .PIO or PT files and It’s quite harder if you are just starting out out and never heard about it But if you guys want to learn any of those too, just comment below, and then I’ll probably do tutorial for you And then the last option Database storage is the one that I usually use when I work on a large project on a serious project and when I’m going to bring another translation and so for that reason This one is pretty hard because it takes a lot of planning beforehand because of the database Optimization, and we really need to decide how we are going to add all those new language. Etc etc So right now. I’m going to show you how to write the code for the first option So now Im here at my PHPStorm and the first thing that we need to create is to actually Create the basic HTML document so first. I’m going to create of course some basic design for our website So let’s see My Amazing Websit okay, and Now the next thing that I want to do is to actually download the Bootstrap because that is what I’m going to use so I’ll go to the then download and Then I will just use compiled CSS And J’s okay so save Go to the folder extract And delete archive, and that’s it and inside here in the CSS folder We have everything that you need so here. I’m going to include it Okay So at the top, I’m going to use the nav bar so I Will say classes is Nav bar and then let’s say you expand on the small devices It will set dark background, and then also let’s say that now bar will be dark. Okay and Now we need to create a list Okay, and then it will have some items like always So navbar item and in this item We are going to have some links, so we’ll say nav bar link Href let’s at the moment. It’s not important And let me maybe just duplicate those So first one let’s say we home The next one let’s say it’ll be pricing And then the last one will be contact Okay So let’s see what do we have so far? Okay, so that’s it this is our nav bar. Maybe let’s set one of those That’s an active and that’s it and now down below. I’m just going to create the Container where we are going to have our website And then the container of course we are going to have One row and maybe let’s justify the content to the center and then here Let’s have one column, so I will say column MD. I am six, and maybe let’s set offset to the three, okay So here I will just say You’ll have one title let’s it’ll be the same as this one here Okay And then I’m just going to have one paragraph, so let’s see this is explanation about my amazing website Okay And let’s see what do we have so far? Okay Good maybe let’s add text to the center and maybe let’s move the container for Maybe 100 pixels Let’s see Okay, looks good and the last thing that I would love to do is to create a footer and then in this footer We are just going to put different languages that are available So we can write it here maybe So I’ll say class footer And we need to create this class okay, and here I will just say like English and then Bosnian which is another option and then here I will just write The class footer so maybe let’s see it will be left up to 0 Position maybe let’s see fixed Let’s say bottom, I will set to 0 Text align to the center Maybe color to the white And I think this should be fine Okay, we don’t see maybe let’s see Background dark Okay, it’s here, but maybe All right set To the 100% Okay, and that’s it so this is our footer here. We have two different languages that we can choose from Here is some title and some explanation about website and other we have many so pretty much those are Three or four different elements that you are going to have on almost any website, and now let’s see how we actually can translate this to the Bosnian language because at the moment you can see that this is all in the English and That one I will set to be the default so let’s see how to do it okay, so I’ll just Close this and Then let’s say here at the top. I’ll write PHP code and Maybe let’s say We will here just include the file config dot PHP so This config we will use on other Pages – okay, so I’ll say new PHP file config ok so first thing that we need to do here is to actually Start a session So I will say session start Okay, and then We will store one variable in this session, and that is to choose the language so say if not Isset Session, let’s say lang We will create one So we will say session length Equal English okay, so this one as you can see is by default if this doesn’t exist or maybe let’s say or Session length is empty, but we’ll make sure that it’s never empty okay, and Then here, let’s say else If isset get language and Get language And not empty Get language, then we are going to change and set different language so Okay, so if you said get language and not empty get language so here, we’ll check if get language Equils English We will set Session length to the English Else Session language equil Bosnia and that’s it and maybe the cool thing and smart thing will be to check here if Session Language Different then get language okay, so if So first we are checking isset get language if does then we want to make sure that it’s different than the one that is already stored in the session and If it is different, and it is not empty then we are going to Check which one it is and then we will set it so here. We can say echo chosen language just to test this part so far and That’s it okay So here it says choose Language English, and then if we say here language equal Bosnian as you can see now it will be changed and If we remove this part and refresh, it’s still Bosnian choosen, okay? and now if we try to change It and maybe try to cheat So maybe let’s say Spanish as you can see it is not going to change because It’s not English Here is we should say if get language Equal Bosnian then okay, just to make sure that it’s not possible to cheat and that’s it So that’s it we will set it to the English For now okay, and that’s it so now the next thing that we need to do is just to load This saved Language okay, so we are going to create two different files so for maybe first Let’s create directory, so let’s say language. Okay, and in the languages we will create PHP file like in English dot PHP and then Let’s create Bosnia dot PHP okay So the array that we need to have is let’s say the name will be language okay, and In this array we are going to translate All the things on the index.php So here if we go from the top first thing that we need to have is title Okay, so I will cut this and paste here so here So say the key will be title and then The translation will be Moj zapanjujući website website Okay, then the next thing that we need to do is To Have home so we will say here Home and then on Bosnian its Pocetna After that we have pricing and contact so here, we’ll say pricing Cijenovnik Okay, and then we have Contact So The word is same, Kontakt Then down below we have title again here, and then we have Description so just say like it’s our description Okay, and then I will say So what do we say here Ovo je opis mog zapanjujuće web stranice And that’s it So now the same thing we need to do for the English so here. You can just do this And then All we need to train is to do just some copy paste so this is Pricing Contact and then here we should paste my Amazing website Okay, and that’s it and now on the Index dot PHP. We just need to call it So here we will say Echo Language and we should say description and It will do the same thing for all other Places so this is title and Then here we have Contact Pricing And the top title again okay, and Of course in the config. We just need to include the name of the File so save require once and then they’ll say language then We will read from the session the language and then Ofcourse the extension of the file and this part should work, so Let’s make a test So now if we refresh English is working really good And now if you change to the Bosnia you can see now that There is a different Language shown and now it says Pocetna, Cjenovnik, Kontakt, Moj zapanjujući website and so on and If we remove this part as you can see it’s still Bosnian, and if we want to change it to the English we do it like this and Here we have different okay, and the last thing that we need to translate is this footer So let’s say In here we will add two more keys to this array so say language English will be English and then language Bosnia Mia and now in the Bosnian Ok we need to change it so this will be Engleski and then Bosanski So let’s try with the English it stays the same and the Bosnia It doesn’t change because Here we didn’t translate it So we’ll say Like this Language And Language Bosnia, so let’s try now Yeah, it is working now, and of course you’ll need to include the links here, so just say like Index.php language And we just need to close those links And that’s it so let’s make a test English-Bosnia now if you choose Bosnian its translated and translated again So pretty much. That’s it guys. I hope that you have enjoyed this video if you do Please like it and shape your friends and of course if you have any questions, please ask in the comment below take care

, , , , , , , , , , , , , , , , , , , ,

Post navigation

92 thoughts on “PHP Multi Language Website Tutorial: Create Dynamic Website In 20 Minutes

  1. Great as always. Looking forward to watch translation with MySQL and Text Files.
    Btw. in WordPress they use similar approach for translation of a theme (with that difference that they compile text files to binary) They generate pot. template text file, then they use it to create .po (language text specific file) which then converts to .mo language specific binary files which is used by WP function __('xyz'). For content translation they usually use WP Database.

  2. how to get auto suggest or autocomplete code while coding, i mean what plugin you use in phpstorm. it would be helpful if u let me know.

  3. please i have two tables tbl_registration and tbl_subjects, i want to select data from this two tables using the while loop and the where clause, how do i go about it? your tutorials have been helping me so much with my php skills… God will bless you… please i need a tutorial on what i just said thanks

  4. I used this method long ago, when I created another website!!
    But instead of text indexes, I used numeric ones, and I got everything messed up, forgetting what index is bound to sentence.

    Please make tutorials, about the other 2 methods as well!
    It would help me very much, 'cause I want to store this social network's translations in database!
    In building a newer, more complex version of a social network (like Facebook, iOrbix, etc)

  5. first thanks for this great video, i just want to ask i downloaded the code from your website run it on my computer but it all shows undefined variables ! is there any problem with the code or wtih my machine, sorry and thanks again

  6. We missed your tutorials for a while, Welcome back Sir! Can you make PHP shopping cart tutorial Please?

  7. Thank you so much for a great video. I would love the see how you would implement the multi-language functionality using a database.

  8. For example when a news item was added to the database. . Here is the question of how the translation process in the front of the site is done from Arabic to English and rtl thanked

  9. Svaka čast brate, Ne znam je li itko ovako dobro objasnio tutorial i tako mi olakšao 🙂 Subscribe sigurno 😉

  10. thank you for this tutorial, it helped me a lot!
    how would the config code have to look, if i wanted to support three languages?

  11. Nice tutorial¡ By the way, which option is more efficiency? I am worried about the loading time because my web page has a lot of text and I am trying to translate it into more than 2 languages. Regards from Spain

  12. Hello, thank you for this useful video. I would like to notice that after you last change on the video, there is no test on what happens a) if the user does not enter a value manually in the GET['lang'] query string parameter in the url and b) if the user supplies manually a language as a query string that does not exist eg ?lang=de . What happens though in both cases, is that that require_once method will hit warning on the browser that it cannot use an empty $lang variable and in second case that the particular array (de) does not exist. I was thinking to put the require_once method inside the valid if statements in order to be used ONLY in cases that the GET['lang'] variable is set. Any opinions on that?

  13. Hi Senaid! Thank you for your great lessons – I really learned a lot. Please make a tutorial for creating dynamic PHP website where the navigation and pages are loaded from PHPmyAdmin, and the user can search for a word or phrase. Almost nothing useful in the net covering that. Best regards from Moscow!

  14. I think you should provide additional video: how to work with paths for a certain language: making or
    Another good video could be about saving preffered language in cookies so nextime user opens the website, he is redireced to a certain locale

  15. Why does your code in config.php in line 13 only work if the second language folder is called bs.php? When I try with fr.php for example it tells me that it is not able to find the path of Languages / bs.php

  16. Again thank you man. I wanted to create a multi language website, but I didn't know how to do it. Your tutorials are really helpful.

  17. Hi and thanks for the video. I just have one question, the coding on the html.php page to display the translation inside the brackets, isn't working on my side. Any ideas on what might cause that?

  18. I like this video because I need 2 language website with no database, my Website is purely meant to be a presentation to audience only. No Database implementation is needed

  19. Thank your for the video =D

    Someone can help me, I want to add html code in a array in php for <b> it's working but not with <a> Thank you for your help.


    $test = array(

    "test" => "test <br> test <a href="">test</a>,



  20. Hi – I enjoyed the tutorial, and tried to implement this on a site I am working on right now. Unfortunately, despite repeatedly checking the entries I made, there seems to be a problem with the code I entered. While I have not yet implemented the switching functionality, e.g., links, I tried switching between the two languages by adding the '?' option after the index file name. No matter which language I enter ('en', 'bs', etc.), the output shows Session language is: Array. Any ideas on what I might have done wrong?

  21. Thank you for taking the time to explain this method for creating a multilingual website. I'm thinking about using this method for the website I'm going to create, but I was wondering what your thoughts are about maintaining the website, even as adding more languages later to the website.

    Then at last i was wondering what the advantages (and disadvantages) are for the other 2 methods. How hard do you think those 2 methods are for someone who has a lot of experience in programming, but not so much in PHP and webdesign overall.

  22. Hi there, cool tutorial but I wrote the first sesion lines before testing correctly but I get HTTP ERROR 500 so I'm not sure what's wrong. Any ideas please? Thanks.

  23. Thank you for this tuto!. I used this method in my project then i realized that my project is quite big. So I'm hoping soon u will make a tutorial for DB storage as well.

  24. Please try to code with a new version stop teaching people php with old version that is not needed in coding classroom

  25. thank you for the tuto ,
    i want to separate the translation values ​​on a text file or csv file how to do it

  26. if(!isset($_SESSION['lang']) || empty($_GET['lang'])){
    $_SESSION['lang'] = 'en';
    else if (isset($_GET['lang']) && $_SESSION['lang'] != $_GET['lang']){
    some code here
    i think this is more correctly because when i remove ?lang part from url it means default language must be set .in your example it remains the last language that was set

  27. Thank you so much for a great video.
    how to customize fonts for each languages in same content by using the multi-language functionality using a database (as in video).
    I wish to see it from you.
    Thank you!

  28. Nothing works, i get errors like " Saw “<?”. Probable cause: Attempt to use an XML processing instruction in HTML. (XML processing instructions are not supported in HTML.)"

Leave a Reply

Your email address will not be published. Required fields are marked *