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

Erick Amezcua
Erick Amezcua
21,826 Points

Handling multilanguage pages

I've finished most Front-End courses and I know a bit of back-end (PHP, to be more specific). The point is that I will start my first web project and I want it available in English and Spanish.

My question is what forms are there to make that possible, I only think about making two versions, but I think that would be lacking in the concept of DRY.

2 Answers

Valeshan Naidoo
Valeshan Naidoo
27,008 Points

From my understanding, you could try using AJAX's get or load method, or you can use jQuery toggle method to go between English and Spanish content. Either way, you'd have to type out the second language content, but not the layout or other elements.

Tobiasz Gala
seal-mask
.a{fill-rule:evenodd;}techdegree
Tobiasz Gala
Full Stack JavaScript Techdegree Student 23,529 Points

You will have to create separate content in your database. You can use cookies to cache which language was chosen or session if you want to implement login functionality. After that, you just select content based on that information (from cookie or session)

// edit I think that I went to far with databases and sessions so in your case the best way is to create one file responsible for layout of the page and include spanish or english text based on cookie variable. For example:

<html>
<head>
<title>...</title>
// etc.
</head>
<body>
<?php
if (cookie == 'spanish') 
   include spanish website
else 
   include english website
?>
</body>
</html>

Really simple example. I don't know if there are any template systems that could easily handle that without too much back-end knowledge.