Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion Personal Profile Page

Lotte Bloem
Lotte Bloem
18,630 Points

I want to use 2 different languages at my site for my first project, is there a course where you guys explain it.

Hi guys, I just started yesterday with my first project. I am dutch and i write everything in English. But i want for my visitors that they also can choose for a dutch language at my site. Can someone help me with the code what i need to use for this. Or is there a course what i can follow?

7 Answers

Moritz Lang
Moritz Lang
25,909 Points

Hello from Germany Lotte :) What did you learn so far? Do you have any experience with PHP? Localizing your website is quite complex for just a beginner project.

Lotte Bloem
Lotte Bloem
18,630 Points

Hi moritz! I didn't follow PHP so far. I try to focus first on html CSS and JavaScript. Maybe when i am done with this tech degree that i will do php after it. I did now just a code with html so people can switch to dutch. But i heard that i also can use javascript for it, or am i wrong?

Moritz Lang
Moritz Lang
25,909 Points

Yes, you can use JavaScript for localization too. But I recommend you to learn the basics first and try to solve this problem later on.

Thale van der Sluijs
Thale van der Sluijs
1,756 Points

Hoi Lotte Bloem,

Als je dat nog niet gedaan hebt kan je een "how to make a website" course volgen, daar leer je HTML en CSS (persoonlijk ben ik nog niet helemaal klaar met deze course, maar ik raad hem echt aan!). Link: https://teamtreehouse.com/library/how-to-make-a-website

Ik hoop dat het lukt. groeten,

Thale van der Sluijs

Lotte Bloem
Lotte Bloem
18,630 Points

hey Thale, Ik heb die eigenlijk allemaal al afgerond maar dat is al meer dan een jaar geleden. Nu moet ik voor mijn tech degree een site maken. Heb het al opgelost met een html code dat ze kunnen kiezen uit engels- of nederlandstalig op mijn site. Maar ik weet dat er ook een javascript code voor moet zijn, maar ik dacht misschien kan ik die dan volgen op treehouse zodat ik weet hoe dat moet.

Mark Casavantes
PLUS
Mark Casavantes
Courses Plus Student 13,401 Points

Lotte,

Are you wanting to make a web-site that uses Dutch and English? If you are, use HTML, CSS and JavaScript. Basically, you would be duplicating your code with one version being in Dutch and one version in English. You could use a button or link to have your visitors select the web pages with the language they prefer.

Best Wishes,

Mark Casavantes

Moritz Lang
Moritz Lang
25,909 Points

I would NOT reccomend you to follow Mark's solution. Imagine you want to add or remove something from your site. You'd have to do it twice in this case. If you decide to add more languages later on you'd have to make the change for every language.

Mark Casavantes
PLUS
Mark Casavantes
Courses Plus Student 13,401 Points

Moritz,

You provided NO solution. Are you considering a translator? Many times a translator is not perfect. Otherwise all text would need to be written twice for each language or as many times as a the website would have languages.

Tell me how you make one change and changes are made to each spoken language without a translator.

<h1> Hola </h1> <h1> Hello </h1>

After your comment Moritz, I looked around to see how others write multi-language websites and found that you either have to use a translator or write a website for each spoken language. In looking around I found that a recommendation was to have a gateway webpage that would direct a visitor to each spoken language website.

http://nationbuilder.com/how_i_create_multilingual_websites

I am familiar with trying to not repeat code, but I do not see how you can avoid a duplicate site for each spoken language. If you change the text in Dutch then you have to change the text in English, or any other spoken languages you have.

If anyone has a better solution I would love to hear it.

Thank you,

Mark Casavantes

Moritz Lang
Moritz Lang
25,909 Points

Hi Mark, I just didn't provide a solution as it might is to complex if you just begin to code. Automated translations in my opinion are pretty bad, so I would not recommend to use it. Basically the right way to translate a page is to write all your views and then write files containing a dictionary with keys and values. In your example you could write a key called "greeting" with the value in the given language. Then you'd call a method that fetches the text and writes it dynamically inside your h1 tag. If you do so, you'd just have to write the text in each language and not write the entire site twice or more.

Therefore I asked her if she has any background in PHP or JavaScript which makes this solution pretty easy to do. If you want to see an example: Laravel handles localization like this.

Also I didn't want to offend you with my comment. I just wanted to say that this should be generaly avoided.

Mark Casavantes
PLUS
Mark Casavantes
Courses Plus Student 13,401 Points

Hi Moritz,

Thank you for your response. We are trying to help Lotte, who I assume is a new programmer. I looked at your Laravel example and looked at some other sources and I agree that Laravel is a solution to her problem by using "en" , "de" "nl" and other language choosers. I believe "nl" is the chooser for Dutch. I see that there are 53 available languages using Laravel. I appreciate learning something new. I am not offended. Now Lotte has two options she can choose from.

Thank you,

Mark Casavantes