General Question

serenityNOW's avatar

How would I add a page-by-page language "switcher" on a website, and should I - details...?

Asked by serenityNOW (3643points) June 3rd, 2013

I have a website that I’ve nearly finished. It’s done both in English and Hungarian. I need to display an option for two language “choices” for the user. The simple solution to change languages/sites, is to put a link on the bottom of the pages to switch languages, and then just be bumped to the homepage of the site, in the opposite language. However, is there some sort of script that would bounce them directly to the page they are already on, just in that opposite language. Example: I’m on the Hungarian page for a “Events” section. If I hit the link at the bottom it would lead me to that exact page, just in English.

I know this is a very specific developer question, but if you were the user, would you even care which page swaps with which?

Observing members: 0 Composing members: 0

3 Answers

rexacoracofalipitorius's avatar

I’ve not done it before, but it should be fairly easy if you have properly separated your content from your presentation.
The nicer-looking way to do it would be to use an
XMLHttpRequest in Javascript to pull the alternate text from the webserver (if you are serving multiple languages, it makes sense to serve them one at a time, yes?) and then use getElementById().InnerHTML to insert the new content into the proper area of the page (your divs all have id’s, right?)

You could also do it strictly on the server side, using templates. This isn’t as pretty, but it saves a layer of complexity on the client side (Javascript adds a lot of complexity.)

To go into much detail on either of these would be to do you a disservice. I can’t explain them as well as MDN covers Javascript or Smarty covers templates.

From a user perspective, I would prefer a translation widget that simply translates the page I’m on without redirecting me anywhere. If you’re doing a page of this complexity you should already be doing it dynamically (I recommend PHP, but that’s just my opinion), which makes it easy to re-use content between pages. Put a translation widget on the head of each page (or somewhere visible) and let me do my own navigation after I can read the current page.

Again, if you are coding all this by hand in HTML and CSS, stop!
Set up a server-side scripting language and a database, or get someone else to help. It’s a pain in the butt to do the first time, but it gives you the ability to do lots of things you can’t do effectively in plain HTML.

serenityNOW's avatar

@rexacoracofalipitorius – “Again, if you are coding all this by hand in HTML and CSS, stop

Yup. I am. To speed tihngs up, I’m just going to have a link that will send them to the alternate site. The suggestion you made about staying on the same page and choose to translate it without going to a new destination would be awesome. (That’s a PHP option and you’d have the other language translation stowed away?) As you’ve possibly seen in my other recent posts, I’m not schooled in any scripting/programming and I only like to add scripts if I know I can edit them. So, adding PHP, even it’s considered “easy” is not an option since if I make a mistake, I’m screwed. I’ve just really came to that realization from another Jellie has suggested if I do something beyond my ability, I’d be messing with my screen name. (My serenity.)

Thanks for the insight though; one more reason to learn this stuff.

rexacoracofalipitorius's avatar

You might already be screwed.
No, you’re not. You’ve kind of got it backwards: if you screw up learning PHP, you just roll back the changes or start over. Use a test server- never ever do development work on your production server and keep your files backed up (really, you should use a VCS, ideally git since it’s the best :^) All you can lose is time.
You don’t need PHP or any server side language necessarily- but you do need Javascript. You don’t have to learn it, but you will need to use it. Trust me when I say that as much as it sucks, it’s better than the alternative.

Doing this translation gig for two languages in HTML / CSS alone will be merely extremely difficult; adding more languages will be worse. It means massive duplication of effort, and even using copy-and-paste, you will mess things up. That’s what humans do. This is not theoretical knowledge. I resisted learning Javascript and did webpages in HTML / CSS for years until I finally bowed to the inevitable.

Doing sophisticated websites without programming is like building a car out of a pile of rocks using a screwdriver. It might be theoretically possible (it isn’t, but I’m not going to get into the comp-sci reasons why not) but it’s not worth the attempt.

You don’t need to learn PHP. What you need is a database. Ideally you will probably want to get someone else to set it up for you. Failing that, I will try to help as best as I can, but I don’t have a lot of time available.

If you can’t get someone to help you into a database (if you have a friend that knows Drupal, then that’s probably the easiest way to set one up) then you could probably get away with having a series of XML files (these can be HTML files with a bit of extra markup) on your server. These files can be called by XMLHTTPRequest to fill in the content of your pages. It will be a little difficult to implement without knowing Javascript, but not if you
1) copy-and-paste from a good example, replacing the relevant stuff; or
2) learn a good client-side framework, which will take care of the details for you.

Most importantly, make sure you know how your webserver works. Apache is pretty well-documented, but very complex. Again, you’ll want someone to help you wade through some of this stuff. I’m an experienced Apache admin and will help as I can- but try to get someone local.

For Knuth’s sake, get someone local to help you! This is a big job. Also, join some local maillists or user groups.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther